hopefully really refactor a bit