Refactor based on Dan's comments