Small fixes and added unit tests