Refactoring and some simple performance improvements by parallelization