Mass refactoring and adding comments, more compilation errors to be fixed