Cleaned up code for API.

Results are now returned in a namedtuple object.