refactor a bit,validate reqeust first