bug-827 changed if to max ;-)