code organization and improvements