http://jclaes.blogspot.com/2011/11/rewriting-if.html