major refactoring/cleanup