In Penknife, fixed nested functions by carrying out the refactoring TODOs.