Organised and modularised the code