simplified to use only 1 variable, cleaned up some comments