Restructred program, modularised, removed redundancy