lots of clean up and fixes
most of the problem was from the last rewrite