Fixed WebAPI bugs

Currently there are many SQL bugs that have appeared and will be fixed
in later commits.