Moved things into packages and cleaned up code