Fixed memory leaks

Also patches contain some other fixes/changes. While testing I have got crash once and couldn't reproduce it. This crash was right after connection to my account while receiving statuses of contacts.