LAI-5: updated error handling and comments