Cleaning up the code and refactoring to namespaces (solves #6 and #7)