most of nested functions working