Visitor ID not getting updated in Javascript tracking API

I don’t know whether it is the expected behaviour or not. Please guide me if I am wrong.

  1. When i push the setUserId event via : window._paq.push(['setUserId', email]), the event is not sent to the piwik server immediately. It is sent only when the next event is pushed (example: page change). Is it the expected behaviour?

  2. When the user is not set, executing window._paq.push([function() { visitorId = this.getVisitorId() }]) returns different visitorIds every time. is it the expected behaviour?

  3. After setting the user in session and when the next event is fired, the visitorId sent in the request and visitor id saved on the piwik server are different. When I try to get the visitor id by window._paq.push([function() { visitorId = this.getVisitorId() }]), the returned local visitorId and the one shown on the piwik dashboard are different.

Please help me out with the issues I am facing.