improved version, using static cache