Refactor LRU replacement into a function