Fix errors in code and add matching spec.