Move common function out to be shared between hybrid and native