Revamped the code for a better output and satisfactory run. Commit #5.