refactor and divide into android & servlet mode.