Refactor and cleanup some classes