Fixed casting errors