massive refactor

this pull requests contains various code changes required as a part of an overhaul of this module. Feel free to ask any questions!