This line is where the big bug was - there's no space between $score and "ORDER..."  That said, it was a bit hard to tell since the use of spaces wasn't very regularized... hence my other edits :-)