Fixed history bug

Rearranged fun to fix history bug