Refactoring, code cleanup