Merge code of google's sample