gh-77 added tests cases + code cleanup