refactorize a bit