Fixed crashes and bugs related to control structures