various minor enhancements
reorganize the code for easier testcases
add example