Fixed error handling as #1