code from google hangout and bugfixes