Rework of locking and input-thread handeling