Added proper handling of invalid parameters