Refactoring, small optimizations.