drawtable js refactored