this fixes #145 + refactoring/performance