added code for saving data and cleaned up unused functions