Added polling and code refactor