Reorganised some code and fixed some bugs