factor out more boilerplate
factor out more common code