update code. fix several rendering bugs