Removed nested functions to support clang (sad regression)