Commented and arranged the whole code for future use.