Fix build errors and add some validation