working - but needs major refactor