Move shared code into a base class, and fix directory structure of specs.
Remove unnecessary encoding directives.