modified code to get it to work