Fixed error handling