added type checking for optional arguments