added insertSpaces function