Several minor fixes
Add some simple tests