move functionality out of main