Moved resonses into else statements so we don't send a response referring to an undefined object on error