cleaned up subgroups, removed magic numbers, added example, works for top and bottom orientations.