Organized,minimized,commented the complete code