Refactor based on Brian's suggestions