Adding some error handling for return values