Some minor performance improvement / refactoring