Refactor the casting into the helper method