Tidying cache function code