Small optimization of the code and better spacing handling