Working code for the back end of the program