code cleaned, commented and beautified