Refactor around `as` function