fixing bugs with detecting types and merging