Some modifications. Not tested