add captcha checking and some refactoring