Factor restrict into a separate operation.
Remove debugging code and update formatting.
Inline max function and fix spacing.