fixed self-modifying finish() bug. added some unit tests for finish()