Implemented back-end for Figures 4 and 5.