Added if support plus other fix ups