added defactorize function