updated the code to handle timestamp window