Memoizing head to avoid re-calculation