help function and some error checking