added continuous polling and optimized a little for performance