Refactored code base

This pull request includes a refactored code base, resulting in more modularized code. It also includes changes previously submitted in pull request #54.