Fixes #7. Some refactoring of api.php and the messages when returning results