come back to the previous version and refactor a little bit