castByElement + fix cast