added testcases and improved functions