Refactor and add license