Added in main() function and arranged code