Bug fix, now seems to work