Moved algorithm into parallel loop