added averaging for better accuracy