Added unit test

- Unit test
- Some minor improvements