working version for refractoring