overhaul for code simplicity, and added aggregate properties support