Put all the function param checks in one function.

This allows to have all this logic in one place and keep the code cleaner.