Added license and fixed a bug