Reduce and simplify code2