some refactoring, + 3% speedup