Some lines are a bit convoluted, using nested lambdas and ternary operators. This might be tolerated for the first version, but such code is difficult to understand and maintain, it could harbour errors. This nested callbacks should be simplified