rearrange code to keep it neat and clear