refactor cast