rearragned code, no functionality change