Refactored REST endpoints and checked that all cases are handled