Correctly reimplement conversion to primitive types