extract into function
implement table using intervals