lockfile functionality and various fixes (there was a bad cache bug)