added lots of new stuff and some locking functionality