Nit: It would be nice to have a validation function. Isn't this duplicate from elsewhere?