Restructuring

Use factory pattern and add tests for all lib files.
v0.2.2