added license
Some refactoring