Some code refactoring. Moved common code into a separate folder.
More code refactoring: Moved core functionality into a separate library.