reorganized api, fixed some bugs, and added patch route.