works well, save for a refactor