refactorize code