Written functioning piece based on John Riley's method.