Redid precalculation code