little bit of factoring and 3 endpoints implemented in json