major rewrite for app engine