Code layout and refactoring