rewrite part of it and moved to servlet vs restlet

Rewrote part of it because restlet stopped working. Also code was far
from perfect. Ported most of the functions but not all yet.