switch ->and_then to ->then_with_f to suppress deprecation warning