Revert "Revert "fixed the entire code""

This reverts commit f4b67d687e962adcdb5584811f32b700de9b8431.