refactor this a bunch