cleaned up code a bit, resolved some global namespacing issues.