Added some locking; fixed build (but the software still doesn't really work).