properly handle required/optional args

[fixes #330]