Make backend more discriminate about what it deletes.

Now, it returns false instead of leaving the schedule in an
invalid state. Also added more logging.
Add error codes and fix some logic bugs.

Error codes are currently only implemented for the remove api
call. The logic now works much more reliably.