update example and refactor to clean up