Updated for beta 5 - type changes, comparing to nil, etc. Simpler code, too.