Fix CS issues, internal documentation, remove deprecated functions and refactor code.