Fixed the space replacement

See code change for simple explanation