re-arrange code