added some comments/debugging code to help show how it works