major refactoring and piping things together