Add threshold parameter to change from serial to parallel computation