added most functionality, and cleaned up some things