General refactoring / code cleanup