Implemented CBC, Refactored some code