Using ! on a non-zero value will always return 0. Also remove some duplicate and superfluous code in other places.