Simplify argument handling

Code is still not great but it should be less confusing now. Also there
is some error handling now.