Make defineType() method more robust