fix pointer type mismatch and misplacement of const