Extraced out common functions