Code tweaks
Add some tests