Optimisation.
Made it so rating is not calculated if it is not needed for output.
Silenced some annoying warnings on gcc.
Edits for style.