added flushQueue method, added synchronized to control access to queue