Made some changes and Shorten the code