restructured main, moved argument check to separate function