fixing/optimizing degree calculation