Fixed a bug which did not let the end signal get through