Bugfixing + added optional profiling