fixed cast bugs