fixed some subtle type errors