added parameters and error checking