Reduce and simplify code