Stopped program from hanging in the end