Added a license, did some refactoring