fixing many bugs with locking and unlocking layers