Refactor thanks to leah's advice