Refactored Pulse Sensor code