Improvements to touch input.

Also changed contrast calculation.