Added better checks for input parameters