refactoring
almost works