re organized code