Added some more structure, may want to reorganise this though.