removed buffer and interval, optimized code