Fixed cf-runagent segfault. Added relevant tests.