Tests and error handling fix