fixed some casting issues