Minor performance and light refactoring