added some modifications to the code