extracted some inner classes to top-level