some code rearragement