updated function to receive inputs
function update
made error more explicit