this code needs to be debugged and tested