Code cleanup and fix for Android 5.0