Added drawing of "caps" to the start/end of each line drawn; cleaned up and reorganized code; light optimization pass