Fix CS and refactoring