Fixed untested syntax errors and commenced some refactoring in order to better promote good programming pactices, the refactoring is by no means finished.