Split argument parsing into a function
Fix file access modes

I must have been sleepy