refactor a bit the code