factor out functions to helpers