Refactor, cleanup, convert all endpoints to JSON