fix bugs and add polling