1. code cleanup
2. added save & load with a dialog
3. fixed some logic.