Apply cca coding standars

Apply cca coding standards. This PR also includes refactoring to reduce complexity.