Fixes and improvements
Added basic tests