Nested functions fixed