save
improved code and optimized for different types of sensor