added error handling and pagination