Added some checks on the function parameters