Fixed bug that caused graphical glitches under certain conditions