Code is stable and computing correct, but slow