Refactor based on Erik's suggestions