Simplify handling of optionalParameters. Fixed some additional bugs (optionalParameters == None).