Fixed 'type' parameter.
Fixed error checking.