Fixed some race conditions

Signed-off-by: Nikita 'webconn' Maslov <wkernelteam@gmail.com>