working finally… cleaning up and modularizing code then testing and improving example