moved code to appropriate files