added more validation and hook_prepare