add logs and optimized the code