refactor to remove duplicate code
clean up demo code