implement rebuild

this patch also contains improved structure for api calls; next commit
will transfer all api calls to use the new system
api: implement move image, store data in DB