Improved backend

Back end rewritten