refactor and create cache