tidied up controller