Fix missing end statement bug