Improved score function