speed improvements. pi fixes