Renamed some method, added comments, moved some code