refactored come common functions, created private functions