Programmed the checking logic
Reformatted code