Did some cleaning up and reorganised some parts of the code