fixed introduced syntax error, and removed visualisation code from main to separte func