Refactored a bit. More detailed return messages from api.