modularised the code