major refactoring and finishing touches