clean up and add some validation