Some fixes and re-arrangement to pass validation