Refactor get and cas to remove duplication