Fix type related bugs