added code to save stats
merged with new control