Updated factory methods to check the type