made most of backend logic for getting the data