fixed missing end statements