Add licence and fix some bug