Revised tested code

This code satisfies the requirements.