This code was primarily written by Marina Polubelova (INRIA).