got rid of passing pointers by ref
added vertical caching, but it slowed this down