Remove type() method and replace by native type checking for performance improvements