Use non-static inner classes instead of holding a reference, as per @kitskub 's suggestion