Removed redundant code and beautified