Added license and fixed a few regressions and race conditions
Added license and fixed a few small errors