Clean up and refactoring round 2