removing all external dependencies, misc refactoring