Calculate a sum for each OS and clean up code