Final code refactoring