updated code flow, cleaned up some things