improved rectangle painting and simlified code
added threadpool