Refactor tests. Fixes #150