Added persistence and fixed bugs along the way