lots of clean up and added some minor validation