REST sends codes 400 and 404

+ refactoring