diff --git a/src/main/java/de/prob2/jupyter/CommandUtils.java b/src/main/java/de/prob2/jupyter/CommandUtils.java
index cf09dee5213d74de095df0e200d00f00c9c33ebf..e7de84b29b525595395b1cdaa5b4af9078652e7e 100644
--- a/src/main/java/de/prob2/jupyter/CommandUtils.java
+++ b/src/main/java/de/prob2/jupyter/CommandUtils.java
@@ -166,7 +166,7 @@ public final class CommandUtils {
 	 * @return the result of the split operation (see {@link SplitResult} for details)
 	 */
 	public static @NotNull SplitResult splitArgs(final @NotNull Parameters parameters, final @NotNull PositionedString argString) {
-		return splitArgs(parameters, argString, argString.getStartPosition() + argString.getValue().length());
+		return splitArgs(parameters, argString, argString.getEndPosition());
 	}
 	
 	private static <T> void validateSplitParameter(final @NotNull ParsedArguments parsed, final @NotNull SplitArguments splitArgs, final @NotNull Parameter<T> param) {
diff --git a/src/main/java/de/prob2/jupyter/PositionedString.java b/src/main/java/de/prob2/jupyter/PositionedString.java
index ba32db9baa8d68f740019ffdd39a64442e55f376..26a14c3cd9f6d6e7de546956382c37eb466421d5 100644
--- a/src/main/java/de/prob2/jupyter/PositionedString.java
+++ b/src/main/java/de/prob2/jupyter/PositionedString.java
@@ -37,6 +37,16 @@ public final class PositionedString {
 		return this.startPosition;
 	}
 	
+	/**
+	 * Return the position of the end of this string.
+	 * This is equivalent to the start position plus the length of the string.
+	 * 
+	 * @return the position of the end of this string
+	 */
+	public int getEndPosition() {
+		return this.getStartPosition() + this.getValue().length();
+	}
+	
 	/**
 	 * <p>
 	 * Return a substring of this string, with the position adjusted accordingly.
diff --git a/src/main/java/de/prob2/jupyter/ProBKernel.java b/src/main/java/de/prob2/jupyter/ProBKernel.java
index 70e1fa66c6f3405df29f99fd2cf5f4054f32cb13..8f7f26a8216e3dafd7b3d6cd5e1e2000a94b6914 100644
--- a/src/main/java/de/prob2/jupyter/ProBKernel.java
+++ b/src/main/java/de/prob2/jupyter/ProBKernel.java
@@ -440,7 +440,7 @@ public final class ProBKernel extends BaseKernel {
 		final SplitCommandCall split = splitCommand(preprocessInput(code));
 		if (this.getCommands().containsKey(split.getName().getValue())) {
 			final Command command = this.getCommands().get(split.getName().getValue());
-			if (at <= split.getName().getStartPosition() + split.getName().getValue().length()) {
+			if (at <= split.getName().getEndPosition()) {
 				// The cursor is somewhere in the command name, show help text for the command.
 				return command.renderHelp();
 			} else if (at < split.getArgString().getStartPosition()) {
@@ -490,13 +490,13 @@ public final class ProBKernel extends BaseKernel {
 	
 	private @Nullable ReplacementOptions completeInternal(final @NotNull PositionedString code, final int at) {
 		final SplitCommandCall split = splitCommand(preprocessInput(code));
-		if (at <= split.getName().getStartPosition() + split.getName().getValue().length()) {
+		if (at <= split.getName().getEndPosition()) {
 			// The cursor is somewhere in the command name, provide command completions.
 			final String prefix = split.getName().substring(0, at - split.getName().getStartPosition()).getValue();
 			return new ReplacementOptions(
 				this.getCommands().keySet().stream().filter(s -> s.startsWith(prefix)).sorted().collect(Collectors.toList()),
 				split.getName().getStartPosition(),
-				split.getName().getStartPosition() + split.getName().getValue().length()
+				split.getName().getEndPosition()
 			);
 		} else if (at < split.getArgString().getStartPosition()) {
 			// The cursor is in the whitespace between the command name and arguments, don't show anything.