Initial code refactoring