Rewrite code and simplify it (better perfs)