added error handling for strange cases