Added function to refine sensor readings