add further error checking on function calls