renamed transformBy to nest and slightly refactored