added debugging flag
moved initialisation to own function
moved game-end commands to own function