lots of cleanup and removed some redundant/bad code