added nonce check and json encode changes