Automatically find number of parameters

In a followup I'll remove the ctx parameter