some code reoganization