Explained original program in comments