Fixing the end bug