Added unit tests
Function unit tests
Struct test
Bugs found using unit tests. Fixed