refator functions