Adjusted code to better match the spec.