changed code organization and cleaned up classes a bit