first refactor done-ish