code refactored. Now it is simpler