Refractored to make tests passs