updated pseudocode & change total variable to sum