Split main script into a module

This addresses issue #54 and splits main script into multiple modules.

The code remains almost the same (except some minor parts), I just split and grouped highly cohesive functions into their own modules.

Regards,