Clean up and refactoring round 1