minor refactoring, removed some excess, undocumented code