Improvements and unit tests