Dependency cleanup, refactoring, bug fixes