Bugfixes and spec tests