fixing the unexpected end issue