Fixes nested functions. Test moved from non-working and added additional test.