cleaned up a lot of code, improved some bits