added feature to automatically remove empty spaces