Minor code fixes and a workaround for Android OS bug