Cleaned up the code a bit for setPosAverage