Refactoring, code cleanup and more comments - Part 2 + Bugfixes