Added license and cleaned up code