fixes on unit construction, agent unit handling

also scattered fixes and cleanup on, you guessed, tests and examples