fixed after extensive testing