Modified to use collections rather than dict+list