Add some locks to prevent some race conditions issues
Fix some issues and add check for the authentication