Fixed pdf display flashing. Fixed lines drawn while changing levels. Cleaned up code a bit.
Merge remote-tracking branch 'origin/master'