needs refactoring .. lots of it