cleaning and refactor code. Working*