fix render glitch; refactor