refactoring
got this stupid thing almost working