Fixes lockfile problems

I expect this to work, but I didn't have the opportunity to test this on linux and windows.

It would be nice if @gurgeh and @Foxboron would test before it makes it into master.

I also did some small housekeepings where I found them.