Fixed more nesting issues to improve readability