Made some changes to fix bugs