Various fixes for away message handling

This makes away message handling more stable and reliable.