Made some changes to improve the code