Unit tests

Unit tests
Some code cleanup