Fixed concurrency issues in paint()