backend mostly done. bugs will be killed later.