working version, needs a doublebuffer