lots of code cleanup, removed redundant stuff, etc