add unit tests and also fix some tiny issues