Move rating code to separate file. Small fixes.

Move rating code to separate file. Small fixes.