Added support for handling optgroups

Fixes #18