Fix CS and move code into new files