Reorganizing some code

also, trying to clean up a lot of functions.