now bug-free (i think)