Added some error handling in stubhandler