add first part of unittest and fix issues found
more unittest and fixes for issue