restructure controller and add exception handler