Refactored all nested control structures