Added Unit tests and fixed code issues