Added logic for rectangle calculation