better error handling for controller