big improvement in the whole code