Refactor based on humph's comments