Checking nonce, adding hooks and events