cleanup casting logic