Update gitignore to ignore ~ files
Fixed not expected behaviour in the algorithm due to a boolean variable not beeing changed when needed