added a condition so that at the end even if they press space bar