Added debugged and improved getPulseWidth function