Patched with Sergiu's first set of bugfixes
Integrated Sergiu's latest commits and rewritten/refactored and checkstyle passed