fixed type detection
improved type detection