Revised implementation.