Added the last steps needed for #58, includings tests.

This also fixes #53.