backport changes from sample app