Fix touch detection algorithm