General code refactoring