fixed 2 bugs with error handling