finish painter.cc and fix bugs