re org code into better structure