Complete code re-structure.

Separated code into different module as entire code in a single file is
becoming more problem in maintaining and extending it.