porting to appengine and refactoring part 1