added more validation/error checking and doc strings