remove extra end statements