fixed score function and added error message