Add lock features
Add locking, fix some stuff, change architecture a bit