sort lists for output
refactoring and moving commands to appropriate files