Implement period_execute rpc call.
Fix some bugs.