refactor nested solutions