refactored table drawing to use common code