modularized  code

Each function is decoupled form the main