Fixed casting bug