simplify code and add if { }