updated the code to fix some errors