reorganizing some code