Improve argument names and add more error checking