Cleanup some code, fix some class bugs