code cleanup, added test cases, improved api usage