fixed nil bug and refactored compensation average