CPK Refactoring adding tests and debuging