Activities code

Flush out most of the activities code and a few bug fixes along the way.