refactored controller with Liz's suggestions