Made api more Ruby-like and fixed some bugs.

This change breaks backwards compatibility, but provides a much more Ruby-like interface, as well as implements some features that were missing.