refactor, still dirty but more readable