Rework code a little