Made some changes, improved code