Getting it better (previous version was looping inifinitely).