refactoring and adding support for Google App Engine