Added license and made some refactoring
Move license to LICENSE file.