Modified locks, added (ugly) debug messages