Bugfix

Fixes a couple of bugs that were causing HEAD not to function and adds some tests.