Refactored code base

## Original Message
This pull request includes a refactored code base, resulting in more modularized code. It also includes changes previously submitted in pull request #54.

## Update
This is a rebase of pull request #57. Duplicate changes with different commit ids have been removed. Additionally I removed unnecessary merge commit messages.