Fix function nesting order