Made some of the code cleaner

got rid of some arbitrary code
cleaned it up
fixed some bugs