made some modification to the code