Simplified the implementation slightly.