diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/.ratings b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/.ratings
index 582e164b9f0c61c9c2eb8b245e467f72dc37f6c5..49e6435ed9469637fbcdcd0e4d6a34ba2e7e3a31 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/.ratings
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/.ratings
@@ -4,6 +4,6 @@ CanTransmissionCatalog.java ec4637eda80234429a9f382a37713588a0fbb83a RED
 ConsoleOutputExecutable.java 5b8c50f2236ad49958a0a0b599a7e60265a6fc06 YELLOW
 HeaderCopyGenerator.java 18239a3adae35256e32dad19df9d8f38acbf7e66 RED
 MultiUnitMainGenerator.java 458754b89c2d79db3fee08baa444424772e40fb7 RED
-PWMActuatorExecutable.java 3273e75ecbb8e41984e8b66cfe8f16bc87256150 YELLOW
+PWMActuatorExecutable.java dbcd7dbf46f7778cce7b52e659646d59ae7a2b3e YELLOW
 RaspberryPIExecutable.java cafff8199da9cc59688289c9c26097e6872e9702 RED
-SingleUnitMainGenerator.java 9ae8b9a5d40c1415720a7bcad2378376474ca70b RED
+SingleUnitMainGenerator.java 6f019af498453ff3c7a615f03ceb46b593e9ff93 RED
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/PWMActuatorExecutable.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/PWMActuatorExecutable.java
index 040518ba9ba50444be8c12ad5eae84acbc4ea001..dbcd7dbf46f7778cce7b52e659646d59ae7a2b3e 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/PWMActuatorExecutable.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/PWMActuatorExecutable.java
@@ -16,17 +16,15 @@
 package org.fortiss.af3.platform.raspberry.generator.executable;
 
 import org.fortiss.af3.component.model.OutputPort;
-import org.fortiss.af3.platform.raspberry.generator.executable.framework.IInitializationExecutable;
 import org.fortiss.af3.platform.raspberry.generator.executable.framework.ISingletonInitializationExecutable;
-import org.fortiss.af3.platform.raspberry.generator.executable.framework.ITerminationExecutable;
+import org.fortiss.af3.platform.raspberry.generator.executable.framework.ISingletonTerminationExecutable;
 import org.fortiss.af3.platform.raspberry.generator.executable.framework.IWriteableExecutable;
 import org.fortiss.af3.platform.raspberry.generator.executable.library.PiHALLibraryExecutableBase;
 import org.fortiss.af3.platform.raspberry.model.ActuatorPWM;
 
 /** Executable for {@link ActuatorPWM}. */
 public class PWMActuatorExecutable extends PiHALLibraryExecutableBase<ActuatorPWM> implements
-		ISingletonInitializationExecutable, IInitializationExecutable, IWriteableExecutable,
-		ITerminationExecutable {
+		ISingletonInitializationExecutable, IWriteableExecutable, ISingletonTerminationExecutable {
 	/** Constructor. */
 	public PWMActuatorExecutable(ActuatorPWM modelElement) {
 		super(modelElement);
@@ -40,51 +38,41 @@ public class PWMActuatorExecutable extends PiHALLibraryExecutableBase<ActuatorPW
 
 	/** {@inheritDoc} */
 	@Override
-	public String getSingletonVariableDeclarationCode() {
-		return "static int actuator_pwm = -1;\n";
-	}
-
-	/** {@inheritDoc} */
-	@Override
-	public String getSingletonInitializationCode() {
-		return "actuator_pwm = temp_actuator_initialize(\"/dev/ttyACM0\");\n";
-	}
-
-	/** {@inheritDoc} */
-	@Override
-	public String getSingletonInitializationIdentifier() {
+	public String getSingletonIdentifier() {
 		// Using header file as unique ID
-		return "temp_actuator.h";
+		return getHeaderFileName();
 	}
 
 	/** {@inheritDoc} */
 	@Override
-	public String getVariableDeclaration(String prefix) {
-		return "";
+	public String getSingletonVariableDeclarationCode(String singletonPrefix) {
+		return "static int " + singletonPrefix + "_actuator_pwm = -1;\n";
 	}
 
 	/** {@inheritDoc} */
 	@Override
-	public String getInitializationCode(String prefix) {
-		return "";
+	public String getSingletonInitializationCode(String singletonPrefix) {
+		return singletonPrefix + "_actuator_pwm = temp_actuator_initialize(\"/dev/ttyACM0\");\n";
 	}
 
 	/** {@inheritDoc} */
 	@Override
-	public String getTerminationCode(String prefix) {
+	public String getSingletonTerminationCode(String singletonPrefix) {
 		return "temp_actuator_terminate();\n";
 	}
 
 	/** {@inheritDoc} */
 	@Override
-	public String getWriteCode(String prefix, OutputPort logicalSignal, String value) {
-		return "temp_actuator_device_set_target(" + prefix + "actuator_pwm, " +
+	public String getWriteCode(String prefix, String singletonPrefix, OutputPort logicalSignal,
+			String value) {
+		return "temp_actuator_device_set_target(" + singletonPrefix + "_actuator_pwm, " +
 				modelElement.getChannelID() + ", " + value + ");\n";
 	}
 
 	/** {@inheritDoc} */
 	@Override
-	public String getNoValWriteCode(String prefix, OutputPort logicalSignal) {
+	public String
+			getNoValWriteCode(String prefix, String singletonPrefix, OutputPort logicalSignal) {
 		return null;
 	}
 }
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/SingleUnitMainGenerator.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/SingleUnitMainGenerator.java
index 8b28a771a036f0acd055591aac295dc519ea5fa9..6f019af498453ff3c7a615f03ceb46b593e9ff93 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/SingleUnitMainGenerator.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/SingleUnitMainGenerator.java
@@ -34,8 +34,10 @@ import org.fortiss.af3.platform.model.ExecutionUnit;
 import org.fortiss.af3.platform.model.PlatformConnectorUnit;
 import org.fortiss.af3.platform.model.Receiver;
 import org.fortiss.af3.platform.model.Transmitter;
-import org.fortiss.af3.platform.raspberry.generator.executable.framework.IInitializationExecutable;
+import org.fortiss.af3.platform.raspberry.generator.executable.framework.IInstanceExecutable;
+import org.fortiss.af3.platform.raspberry.generator.executable.framework.IInstanceInitializationExecutable;
 import org.fortiss.af3.platform.raspberry.generator.executable.framework.IReadableExecutable;
+import org.fortiss.af3.platform.raspberry.generator.executable.framework.ISingletonExecutable;
 import org.fortiss.af3.platform.raspberry.generator.executable.framework.ISingletonInitializationExecutable;
 import org.fortiss.af3.platform.raspberry.generator.executable.framework.IWriteableExecutable;
 import org.fortiss.af3.platform.raspberry.model.RaspberryPi;
@@ -56,6 +58,10 @@ class SingleUnitMainGenerator {
 	/** The map from platform elements to executables. */
 	private Map<PlatformConnectorUnit, ExecutableBase<?>> platformConnector2ExecutableBase =
 			new HashMap<>();
+	/** The map from singleton identifiers to singleton prefixes. */
+	private Map<String, String> singletonPrefixMap = new HashMap<>();
+	/** The map from executables to instance prefixes. */
+	private Map<ExecutableBase<?>, String> instancePrefixMap = new HashMap<>();
 
 	/** Constructor. */
 	public SingleUnitMainGenerator(RaspberryPi executionUnit,
@@ -69,13 +75,14 @@ class SingleUnitMainGenerator {
 		this.headers = headers;
 		this.context = context;
 		this.platformConnector2ExecutableBase.putAll(platformConnector2ExecutableBase);
+		computePrefixes();
 	}
 
 	/** Creates the main.c file for deployments with a single execution units. */
 	public AbstractUnit createSingleUnitMain() {
 		String includes = createIncludes();
 		String initCode = createInitCode();
-		String sensorVariables = createVariables(deployedComponents, deployedPorts);
+		String sensorVariables = createVariables();
 		String workerCode = createWorkerCode(deployedComponents, deployedPorts);
 		return getSingleUnitMainCFile(executionUnit.getName(), executionUnit.getCycleTime(),
 				includes, initCode, workerCode, sensorVariables);
@@ -123,123 +130,128 @@ class SingleUnitMainGenerator {
 	}
 
 	/** Create the Sensor Variables and functions. */
-	private String createVariables(List<Pair<ExecutionUnit, Component>> deployedComponents,
-			List<Pair<PlatformConnectorUnit, Port>> deployedPorts) {
+	private String createVariables() {
 		StringBuilder sb = new StringBuilder();
 		Set<String> singletonInitDone = new HashSet<>();
 		for(PlatformConnectorUnit pcu : platformConnector2ExecutableBase.keySet()) {
 			ExecutableBase<?> exec = platformConnector2ExecutableBase.get(pcu);
+			String sPrefix = null;
 			if(exec instanceof ISingletonInitializationExecutable) {
 				ISingletonInitializationExecutable singletonExec =
 						(ISingletonInitializationExecutable)exec;
-				String ident = singletonExec.getSingletonInitializationIdentifier();
+				// check if variable declaration was already included
+				String ident = singletonExec.getSingletonIdentifier();
+				sPrefix = singletonPrefixMap.get(ident);
 				if(!singletonInitDone.contains(ident)) {
 					singletonInitDone.add(ident);
-					sb.append(singletonExec.getSingletonVariableDeclarationCode());
+					sb.append(singletonExec.getSingletonVariableDeclarationCode(sPrefix));
 				}
 			}
-			if(exec instanceof IInitializationExecutable) {
-				IInitializationExecutable initExec = (IInitializationExecutable)exec;
-				String prefix = getPrefix(pcu);
-				sb.append(initExec.getVariableDeclaration(prefix));
+			// sPrefix is set by first if-block or remains null
+			if(exec instanceof IInstanceInitializationExecutable) {
+				IInstanceInitializationExecutable initExec =
+						(IInstanceInitializationExecutable)exec;
+				String iPrefix = instancePrefixMap.get(initExec);
+				sb.append(initExec.getVariableDeclaration(iPrefix, sPrefix));
 			}
 		}
-		// if(usePWM) {
-		// sb.append("int maestro_fd = -1;\n");
-		// }
-		// if(useDigits) {
-		// sb.append("SegmentDisplay4x7 segment_display;\n");
-		// sb.append("static void set_led_display (SegmentDisplay4x7 *segment_display, uint16_t value, bool showHex) {\n");
-		// sb.append("static const uint8_t digits[] = {0x3f,0x06,0x5b,0x4f,\n");
-		// sb.append("                                 0x66,0x6d,0x7d,0x07,\n");
-		// sb.append("                                 0x7f,0x6f,0x77,0x7c,\n");
-		// sb.append("                                 0x39,0x5e,0x79,0x71};\n");
-		// sb.append("if(showHex) {\n");
-		// sb.append("uint8_t segments[4] = {digits[(value >> 12) & 0x0F], digits[(value >> 8) & 0x0F], digits[(value >> 4) & 0x0F], digits[value & 0x0F]};\n");
-		// sb.append("segment_display_4x7_set_segments(segment_display, segments, 5, false);\n");
-		// sb.append("} else {\n");
-		// sb.append("uint8_t segments[4] = {digits[(value%10000)/1000], digits[(value%1000)/100], digits[(value%100)/10], digits[value%10]};\n");
-		// sb.append("segment_display_4x7_set_segments(segment_display, segments, 5, false);\n");
-		// sb.append("}\n");
-		// sb.append("}\n\n");
-		// }
-		// if(useLEDButton) {
-		// // for(Pair<PlatformConnectorUnit, Port> p : deployedPorts) {
-		// for(String uid : ledButtons.keySet()) {
-		// sb.append("RGBLEDButton rlb_" + uid + ";\n");
-		// }
-		// for(String[] arr : ledButtonsLocalVariable.values()) {
-		// for(String var : arr) {
-		// sb.append("uint8_t " + var + " = 0;\n");
-		// }
-		// }
-		// // extractRGBforLEDButton(p);
-		// // }
-		// }
-		// if(useUS) {
-		// sb.append("uint16_t ultra_sonic_A;\n");
-		// sb.append("uint64_t us_A_last_cb_time = 0;\n");
-		// sb.append("char* uid_us_A = \"zpW\";\n");
-		// sb.append("void us_A_callback(uint16_t distance, void *data) {\n");
-		// sb.append("ultra_sonic_A = distance;\n");
-		// sb.append("us_A_last_cb_time = time_util_get_current_micros();\n");
-		// sb.append("}\n");
-		// sb.append("uint16_t ultra_sonic_B;\n");
-		// sb.append("uint64_t us_B_last_cb_time = 0;\n");
-		// sb.append("char* uid_us_B = \"zqN\";\n");
-		// sb.append("void us_B_callback(uint16_t distance, void *data) {\n");
-		// sb.append("ultra_sonic_B = distance;\n");
-		// sb.append("us_B_last_cb_time = time_util_get_current_micros();\n");
-		// sb.append("}\n\n");
-		// }
-		// if(useLaser) {
-		// sb.append("int16_t laser_distance;\n");
-		// sb.append("uint64_t laser_last_cb_time = 0;\n");
-		// sb.append("void laser_callback(uint16_t distance, void *data) {\n");
-		// sb.append("laser_distance = distance;\n");
-		// sb.append("laser_last_cb_time = time_util_get_current_micros();\n");
-		// sb.append("}\n\n");
-		// }
-		// if(useACC) {
-		// sb.append("float Q = 0.022;\n");
-		// sb.append("float R = 0.917;\n");
-		// sb.append("float estimates[9] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};\n");
-		// sb.append("float last_p[9] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};\n");
-		// sb.append("float kalman_filter(float value, int sensor) {\n");
-		// sb.append("if(sensor < 0 || sensor > 5) return -1;\n");
-		// sb.append("float temp_est = estimates[sensor];\n");
-		// sb.append("float p_temp = last_p[sensor] + Q;\n");
-		// sb.append("float K = p_temp * (1.0/(p_temp + R));\n");
-		// sb.append("float est = temp_est + K * (value - temp_est);\n");
-		// sb.append("float P = (1-K)*p_temp;\n");
-		// sb.append("last_p[sensor] = P;\n");
-		// sb.append("estimates[sensor] = est;\n");
-		// sb.append("return est;\n");
-		// sb.append("}\n\n");
-		// sb.append("float acceleration_X, acceleration_Y, acceleration_Z;\n");
-		// sb.append("uint64_t acc_last_cb_time = 0;\n");
-		// sb.append("void acc_callback(int16_t x, int16_t y, int16_t z, void* data) {\n");
-		// sb.append("if (abs(x - acceleration_X) > 2 * 10 * 100 ||\n");
-		// sb.append("abs(y - acceleration_Y) > 2 * 10 * 100 ||\n");
-		// sb.append("abs(z - acceleration_Z) > 2 * 10 * 100)\n");
-		// sb.append("    return;\n");
-		// sb.append("acceleration_X = kalman_filter(x, 0) / 100.0;\n");
-		// sb.append("acceleration_Y = kalman_filter(y, 1) / 100.0;\n");
-		// sb.append("acceleration_Z = kalman_filter(z, 2) / 100.0;\n");
-		// sb.append("acc_last_cb_time = time_util_get_current_micros();\n");
-		// sb.append("}\n\n");
-		// sb.append("float angularVelocity_X, angularVelocity_Y, angularVelocity_Z;\n");
-		// sb.append("uint64_t angV_last_cb_time = 0;\n");
-		// sb.append("void angV_callback(int16_t x, int16_t y, int16_t z, void* data) {\n");
-		// sb.append("angularVelocity_X = kalman_filter(x, 3) / 16;\n");
-		// sb.append("angularVelocity_Y = kalman_filter(y, 4) / 16;\n");
-		// sb.append("angularVelocity_Z = kalman_filter(z, 5) / 16;\n");
-		// sb.append("angV_last_cb_time = time_util_get_current_micros();\n");
-		// sb.append("}\n\n");
-		// }
 		return sb.toString();
 	}
 
+	// if(usePWM) {
+	// sb.append("int maestro_fd = -1;\n");
+	// }
+	// if(useDigits) {
+	// sb.append("SegmentDisplay4x7 segment_display;\n");
+	// sb.append("static void set_led_display (SegmentDisplay4x7 *segment_display, uint16_t value, bool showHex) {\n");
+	// sb.append("static const uint8_t digits[] = {0x3f,0x06,0x5b,0x4f,\n");
+	// sb.append("                                 0x66,0x6d,0x7d,0x07,\n");
+	// sb.append("                                 0x7f,0x6f,0x77,0x7c,\n");
+	// sb.append("                                 0x39,0x5e,0x79,0x71};\n");
+	// sb.append("if(showHex) {\n");
+	// sb.append("uint8_t segments[4] = {digits[(value >> 12) & 0x0F], digits[(value >> 8) & 0x0F], digits[(value >> 4) & 0x0F], digits[value & 0x0F]};\n");
+	// sb.append("segment_display_4x7_set_segments(segment_display, segments, 5, false);\n");
+	// sb.append("} else {\n");
+	// sb.append("uint8_t segments[4] = {digits[(value%10000)/1000], digits[(value%1000)/100], digits[(value%100)/10], digits[value%10]};\n");
+	// sb.append("segment_display_4x7_set_segments(segment_display, segments, 5, false);\n");
+	// sb.append("}\n");
+	// sb.append("}\n\n");
+	// }
+	// if(useLEDButton) {
+	// // for(Pair<PlatformConnectorUnit, Port> p : deployedPorts) {
+	// for(String uid : ledButtons.keySet()) {
+	// sb.append("RGBLEDButton rlb_" + uid + ";\n");
+	// }
+	// for(String[] arr : ledButtonsLocalVariable.values()) {
+	// for(String var : arr) {
+	// sb.append("uint8_t " + var + " = 0;\n");
+	// }
+	// }
+	// // extractRGBforLEDButton(p);
+	// // }
+	// }
+	// if(useUS) {
+	// sb.append("uint16_t ultra_sonic_A;\n");
+	// sb.append("uint64_t us_A_last_cb_time = 0;\n");
+	// sb.append("char* uid_us_A = \"zpW\";\n");
+	// sb.append("void us_A_callback(uint16_t distance, void *data) {\n");
+	// sb.append("ultra_sonic_A = distance;\n");
+	// sb.append("us_A_last_cb_time = time_util_get_current_micros();\n");
+	// sb.append("}\n");
+	// sb.append("uint16_t ultra_sonic_B;\n");
+	// sb.append("uint64_t us_B_last_cb_time = 0;\n");
+	// sb.append("char* uid_us_B = \"zqN\";\n");
+	// sb.append("void us_B_callback(uint16_t distance, void *data) {\n");
+	// sb.append("ultra_sonic_B = distance;\n");
+	// sb.append("us_B_last_cb_time = time_util_get_current_micros();\n");
+	// sb.append("}\n\n");
+	// }
+	// if(useLaser) {
+	// sb.append("int16_t laser_distance;\n");
+	// sb.append("uint64_t laser_last_cb_time = 0;\n");
+	// sb.append("void laser_callback(uint16_t distance, void *data) {\n");
+	// sb.append("laser_distance = distance;\n");
+	// sb.append("laser_last_cb_time = time_util_get_current_micros();\n");
+	// sb.append("}\n\n");
+	// }
+	// if(useACC) {
+	// sb.append("float Q = 0.022;\n");
+	// sb.append("float R = 0.917;\n");
+	// sb.append("float estimates[9] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};\n");
+	// sb.append("float last_p[9] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};\n");
+	// sb.append("float kalman_filter(float value, int sensor) {\n");
+	// sb.append("if(sensor < 0 || sensor > 5) return -1;\n");
+	// sb.append("float temp_est = estimates[sensor];\n");
+	// sb.append("float p_temp = last_p[sensor] + Q;\n");
+	// sb.append("float K = p_temp * (1.0/(p_temp + R));\n");
+	// sb.append("float est = temp_est + K * (value - temp_est);\n");
+	// sb.append("float P = (1-K)*p_temp;\n");
+	// sb.append("last_p[sensor] = P;\n");
+	// sb.append("estimates[sensor] = est;\n");
+	// sb.append("return est;\n");
+	// sb.append("}\n\n");
+	// sb.append("float acceleration_X, acceleration_Y, acceleration_Z;\n");
+	// sb.append("uint64_t acc_last_cb_time = 0;\n");
+	// sb.append("void acc_callback(int16_t x, int16_t y, int16_t z, void* data) {\n");
+	// sb.append("if (abs(x - acceleration_X) > 2 * 10 * 100 ||\n");
+	// sb.append("abs(y - acceleration_Y) > 2 * 10 * 100 ||\n");
+	// sb.append("abs(z - acceleration_Z) > 2 * 10 * 100)\n");
+	// sb.append("    return;\n");
+	// sb.append("acceleration_X = kalman_filter(x, 0) / 100.0;\n");
+	// sb.append("acceleration_Y = kalman_filter(y, 1) / 100.0;\n");
+	// sb.append("acceleration_Z = kalman_filter(z, 2) / 100.0;\n");
+	// sb.append("acc_last_cb_time = time_util_get_current_micros();\n");
+	// sb.append("}\n\n");
+	// sb.append("float angularVelocity_X, angularVelocity_Y, angularVelocity_Z;\n");
+	// sb.append("uint64_t angV_last_cb_time = 0;\n");
+	// sb.append("void angV_callback(int16_t x, int16_t y, int16_t z, void* data) {\n");
+	// sb.append("angularVelocity_X = kalman_filter(x, 3) / 16;\n");
+	// sb.append("angularVelocity_Y = kalman_filter(y, 4) / 16;\n");
+	// sb.append("angularVelocity_Z = kalman_filter(z, 5) / 16;\n");
+	// sb.append("angV_last_cb_time = time_util_get_current_micros();\n");
+	// sb.append("}\n\n");
+	// }
+
 	/**
 	 * @param p
 	 */
@@ -287,10 +299,15 @@ class SingleUnitMainGenerator {
 	/** Creates the read code for the given receiver and port. */
 	private String createWriteCode(Transmitter transmitter, OutputPort outport) {
 		ExecutableBase<?> exec = platformConnector2ExecutableBase.get(transmitter);
+		String sPrefix = null;
+		if(exec instanceof ISingletonExecutable) {
+			sPrefix = singletonPrefixMap.get(((ISingletonExecutable)exec).getSingletonIdentifier());
+		}
+		String iPrefix = instancePrefixMap.get(exec);
 		if(exec instanceof IWriteableExecutable) {
 			IWriteableExecutable wexec = (IWriteableExecutable)exec;
 			// TODO: NoVal support
-			return wexec.getWriteCode(getPrefix(transmitter), outport, portName(outport));
+			return wexec.getWriteCode(iPrefix, sPrefix, outport, portName(outport));
 		}
 		return "FIXME(\"No executable available to write " + outport.getName() + " to " +
 				transmitter.getName() + "\");\n";
@@ -299,10 +316,15 @@ class SingleUnitMainGenerator {
 	/** Creates the read code for the given receiver and port. */
 	private String createReadCode(Receiver receiver, InputPort inport) {
 		ExecutableBase<?> exec = platformConnector2ExecutableBase.get(receiver);
+		String sPrefix = null;
+		if(exec instanceof ISingletonExecutable) {
+			sPrefix = singletonPrefixMap.get(((ISingletonExecutable)exec).getSingletonIdentifier());
+		}
+		String iPrefix = instancePrefixMap.get(exec);
 		if(exec instanceof IReadableExecutable) {
 			IReadableExecutable rexec = (IReadableExecutable)exec;
 			// TODO: NoVal support
-			return rexec.getReadCode(getPrefix(receiver), inport);
+			return rexec.getReadCode(iPrefix, sPrefix, inport);
 		}
 		return "FIXME\"No executable available to read " + inport.getName() + " from " +
 				receiver.getName() + "\");\n";
@@ -314,27 +336,49 @@ class SingleUnitMainGenerator {
 		Set<String> singletonInitDone = new HashSet<>();
 		for(PlatformConnectorUnit pcu : platformConnector2ExecutableBase.keySet()) {
 			ExecutableBase<?> exec = platformConnector2ExecutableBase.get(pcu);
+			String sPrefix = null;
 			if(exec instanceof ISingletonInitializationExecutable) {
 				ISingletonInitializationExecutable singletonExec =
 						(ISingletonInitializationExecutable)exec;
-				String ident = singletonExec.getSingletonInitializationIdentifier();
+				String ident = singletonExec.getSingletonIdentifier();
+				sPrefix = singletonPrefixMap.get(ident);
 				if(!singletonInitDone.contains(ident)) {
 					singletonInitDone.add(ident);
-					sb.append(singletonExec.getSingletonInitializationCode());
+					sb.append(singletonExec.getSingletonInitializationCode(sPrefix));
 				}
 			}
-			if(exec instanceof IInitializationExecutable) {
-				IInitializationExecutable initExec = (IInitializationExecutable)exec;
-				String prefix = getPrefix(pcu);
-				sb.append(initExec.getInitializationCode(prefix));
+			// sPrefix is set in the first if-block or is null
+			if(exec instanceof IInstanceInitializationExecutable) {
+				IInstanceInitializationExecutable initExec =
+						(IInstanceInitializationExecutable)exec;
+				String iPrefix = instancePrefixMap.get(initExec);
+				sb.append(initExec.getInitializationCode(iPrefix, sPrefix));
 			}
 		}
 		return sb.toString();
 	}
 
-	/** Returns a unique prefix for this {@link PlatformConnectorUnit}. */
-	private String getPrefix(PlatformConnectorUnit pcu) {
-		return pcu.getName().replace(' ', '_') + pcu.getId() + '_';
+	/** A counter to produce unique identifiers. */
+	private int prefixCounter = 1;
+
+	/** Computes the singleton and instance prefixes for all executables. */
+	private void computePrefixes() {
+		for(PlatformConnectorUnit pcu : platformConnector2ExecutableBase.keySet()) {
+			ExecutableBase<?> exec = platformConnector2ExecutableBase.get(pcu);
+			if(exec instanceof ISingletonExecutable) {
+				String id = ((ISingletonExecutable)exec).getSingletonIdentifier();
+				if(!singletonPrefixMap.containsKey(id)) {
+					String sPrefix = "singleton_" + (prefixCounter++);
+					singletonPrefixMap.put(id, sPrefix);
+				}
+			}
+			if(exec instanceof IInstanceExecutable) {
+				if(!instancePrefixMap.containsKey(exec)) {
+					String iPrefix = "instance_" + (prefixCounter++);
+					instancePrefixMap.put(exec, iPrefix);
+				}
+			}
+		}
 	}
 
 	private void temp() {
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/.ratings b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/.ratings
index e883d33319a9f49abe69966cee96389f585ef636..03367d7c77b1db5fc03a009e3f6b4aecd69f7ac9 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/.ratings
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/.ratings
@@ -1,8 +1,11 @@
-IInitializationExecutable.java 1633bcca794b274fe27bb009ff18f7a7acecd79e YELLOW
+IInstanceExecutable.java 3affc638b5802896ff7bfae6f9185fc0dfa8c8d2 YELLOW
+IInstanceInitializationExecutable.java 692ea1d3245101e6871b610b6b2acbf09ac5b16f YELLOW
+IInstanceTerminationExecutable.java 7be0257c229e85e223e72a19d21fd4c7c5db1750 YELLOW
 IRasPiHeaderExecutable.java f14b5714e7b982e097f6ac6e95eb91223a30d048 YELLOW
 IRasPiLibraryBasedExecutable.java cf3548f22185e666fdcf6d4658b783734c0e5e8e YELLOW
 IRasPiSourceBasedExecutable.java 79646213964346ace17013f5c8df5de13dafb1f0 YELLOW
-IReadableExecutable.java 14fdbe86fd5a31f1fe073da4c77f4ea1675e293e YELLOW
-ISingletonInitializationExecutable.java f654ebf031b805e10ef6e0f0fbf3df179b20e20e YELLOW
-ITerminationExecutable.java 61a81fcc3be00df33cf96e764d03686a423abcd9 YELLOW
-IWriteableExecutable.java 9bbb6b6644f69e3b3ba9255862b89d79bcc00c2c YELLOW
+IReadableExecutable.java fdab374944e016be0f3c891af9b992627f16b9c3 YELLOW
+ISingletonExecutable.java d7a794f50cf4746fa9378ffaa89283130b5273b1 YELLOW
+ISingletonInitializationExecutable.java fe042d336b3f9c618051d6598dfad882292b554f YELLOW
+ISingletonTerminationExecutable.java 2bd04ac893bedfd44ca4e73a27dd636873d8b64a YELLOW
+IWriteableExecutable.java 94296a1c47dec576443faf93bbcf7f8d668b834b YELLOW
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IInstanceExecutable.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IInstanceExecutable.java
new file mode 100644
index 0000000000000000000000000000000000000000..3affc638b5802896ff7bfae6f9185fc0dfa8c8d2
--- /dev/null
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IInstanceExecutable.java
@@ -0,0 +1,26 @@
+/*-------------------------------------------------------------------------+
+| Copyright 2018 fortiss GmbH                                              |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.af3.platform.raspberry.generator.executable.framework;
+
+/**
+ * Marker interface for {@link IInstanceInitializationExecutable} and
+ * {@link IInstanceTerminationExecutable}.
+ * 
+ * @author hoelzl
+ */
+public interface IInstanceExecutable {
+	// marker interface only
+}
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IInstanceInitializationExecutable.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IInstanceInitializationExecutable.java
new file mode 100644
index 0000000000000000000000000000000000000000..692ea1d3245101e6871b610b6b2acbf09ac5b16f
--- /dev/null
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IInstanceInitializationExecutable.java
@@ -0,0 +1,42 @@
+/*-------------------------------------------------------------------------+
+| Copyright 2018 fortiss GmbH                                              |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.af3.platform.raspberry.generator.executable.framework;
+
+import org.fortiss.af3.platform.language.executable.ExecutableBase;
+
+/**
+ * Interface for {@link ExecutableBase}s, which require initialization including the definition
+ * static variables in the main program (e.g. a Unix file descriptor) on an instance level, e.g.,
+ * every sensor of a certain type has its own instance data.
+ * 
+ * @author hoelzl
+ */
+public interface IInstanceInitializationExecutable extends IInstanceExecutable {
+	/**
+	 * Returns the variable declarations needed by this executable. The prefix is given by the code
+	 * generator to ensure uniqueness of variables for platform elements of the same type. If the
+	 * implementing class also implements {@link ISingletonInitializationExecutable} the
+	 * {@code singletonPrefix} is non-null and the same as supplied to the methods of the latter
+	 * interface.
+	 */
+	String getVariableDeclaration(String prefix, String singletonPrefix);
+
+	/**
+	 * Returns the initialization code for the given {@code prefix} and, optionally,
+	 * {@code singletonPrefix}.
+	 */
+	String getInitializationCode(String prefix, String singletonPrefix);
+}
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/ITerminationExecutable.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IInstanceTerminationExecutable.java
similarity index 81%
rename from org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/ITerminationExecutable.java
rename to org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IInstanceTerminationExecutable.java
index 61a81fcc3be00df33cf96e764d03686a423abcd9..7be0257c229e85e223e72a19d21fd4c7c5db1750 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/ITerminationExecutable.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IInstanceTerminationExecutable.java
@@ -19,10 +19,12 @@ import org.fortiss.af3.platform.language.executable.ExecutableBase;
 
 /**
  * Interface for {@link ExecutableBase}s, which require to be terminated during program shutdown.
+ * The termination code is included for every executable instance with the {@code prefix} provided
+ * by the code generator.
  * 
  * @author hoelzl
  */
-public interface ITerminationExecutable {
-	/** Returns an termination code. */
-	String getTerminationCode(String prefix);
+public interface IInstanceTerminationExecutable extends IInstanceExecutable {
+	/** Returns an termination code for the given {@code prefix}. */
+	String getInstanceTerminationCode(String prefix);
 }
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IReadableExecutable.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IReadableExecutable.java
index 14fdbe86fd5a31f1fe073da4c77f4ea1675e293e..fdab374944e016be0f3c891af9b992627f16b9c3 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IReadableExecutable.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IReadableExecutable.java
@@ -24,11 +24,11 @@ import org.fortiss.af3.component.model.InputPort;
  */
 public interface IReadableExecutable {
 	/** Returns the read code for the given port. */
-	String getReadCode(String prefix, InputPort logicalSignal);
+	String getReadCode(String prefix, String singletonPrefix, InputPort logicalSignal);
 
 	/**
 	 * Returns the read code to determine whether the value of the platform element is NoVal. May
 	 * return {@code null}, to indicate that NoVal is not supported.
 	 */
-	String getNoValReadCode(String prefix, InputPort logicalSignal);
+	String getNoValReadCode(String prefix, String singletonPrefix, InputPort logicalSignal);
 }
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/ISingletonExecutable.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/ISingletonExecutable.java
new file mode 100644
index 0000000000000000000000000000000000000000..d7a794f50cf4746fa9378ffaa89283130b5273b1
--- /dev/null
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/ISingletonExecutable.java
@@ -0,0 +1,27 @@
+/*-------------------------------------------------------------------------+
+| Copyright 2018 fortiss GmbH                                              |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.af3.platform.raspberry.generator.executable.framework;
+
+/**
+ * Interface for executables, which require singleton support (for variable declarations,,
+ * initialization, and termination) .
+ * 
+ * @author hoelzl
+ */
+public interface ISingletonExecutable {
+	/** Returns the singleton identifier. */
+	public abstract String getSingletonIdentifier();
+}
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/ISingletonInitializationExecutable.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/ISingletonInitializationExecutable.java
index f654ebf031b805e10ef6e0f0fbf3df179b20e20e..fe042d336b3f9c618051d6598dfad882292b554f 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/ISingletonInitializationExecutable.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/ISingletonInitializationExecutable.java
@@ -16,21 +16,23 @@
 package org.fortiss.af3.platform.raspberry.generator.executable.framework;
 
 /**
- * Interface implemented by platform-specific executables, which need
- * initialization during system start-up. In contrast to {@link IInitializationExecutable},
- * if there are more than one actuator or sensor with the singleton identifier, the
- * common initialization code is only included once in the generated code and it is included before
- * all other initialization code.
+ * Interface implemented by platform-specific executables, which require singleton initialization
+ * including the definition of static singleton variables in the main program, e.g., every sensor
+ * of a certain type shares a single IP connection with the other instances.
+ * <P>
+ * In contrast to {@link IInstanceInitializationExecutable}, if there are more than one actuator or
+ * sensor with the singleton identifier, the common initialization code is only included once in the
+ * generated code and it is included before all other initialization code.
  * 
  * @author hoelzl
  */
-public interface ISingletonInitializationExecutable {
-	/** Returns the singleton identifier. */
-	String getSingletonInitializationIdentifier();
-
-	/** Returns the code to initialize local variables used by the initialization code. */
-	String getSingletonVariableDeclarationCode();
+public interface ISingletonInitializationExecutable extends ISingletonExecutable {
+	/**
+	 * Returns the code to initialize local variables used by the code. Implementors may use the
+	 * provided {@code singletonPrefix} to create unique variable names.
+	 */
+	String getSingletonVariableDeclarationCode(String singletonPrefix);
 
 	/** Returns the common initialization code. */
-	String getSingletonInitializationCode();
+	String getSingletonInitializationCode(String singletonPrefix);
 }
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IInitializationExecutable.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/ISingletonTerminationExecutable.java
similarity index 70%
rename from org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IInitializationExecutable.java
rename to org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/ISingletonTerminationExecutable.java
index 1633bcca794b274fe27bb009ff18f7a7acecd79e..2bd04ac893bedfd44ca4e73a27dd636873d8b64a 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IInitializationExecutable.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/ISingletonTerminationExecutable.java
@@ -18,18 +18,14 @@ package org.fortiss.af3.platform.raspberry.generator.executable.framework;
 import org.fortiss.af3.platform.language.executable.ExecutableBase;
 
 /**
- * Interface for {@link ExecutableBase}s, which require initialization including static variables in
- * the main program (e.g. a Unix file descriptor).
+ * Interface for singleton {@link ExecutableBase}s, which require to be terminated during program
+ * shutdown. The termination code is only executed once for all executables, which return the same
+ * identifier with {@link #getSingletonIdentifier()}. The executable is provided a
+ * {@code singletonPrefix} to ensure uniqueness of identifiers.
  * 
  * @author hoelzl
  */
-public interface IInitializationExecutable {
-	/**
-	 * Returns the variable declarations needed by this executable. The prefix is given by the code
-	 * generator to ensure uniqueness of variables for platform elements of the same type.
-	 */
-	String getVariableDeclaration(String prefix);
-
-	/** Returns the initialization code. */
-	String getInitializationCode(String prefix);
+public interface ISingletonTerminationExecutable extends ISingletonExecutable {
+	/** Returns an termination code for the given {@code singletonPrefix}. */
+	String getSingletonTerminationCode(String singletonPrefix);
 }
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IWriteableExecutable.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IWriteableExecutable.java
index 9bbb6b6644f69e3b3ba9255862b89d79bcc00c2c..94296a1c47dec576443faf93bbcf7f8d668b834b 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IWriteableExecutable.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/framework/IWriteableExecutable.java
@@ -24,11 +24,12 @@ import org.fortiss.af3.component.model.OutputPort;
  */
 public interface IWriteableExecutable {
 	/** Returns the write code for the given port. */
-	String getWriteCode(String prefix, OutputPort logicalSignal, String value);
+	String getWriteCode(String prefix, String singletonPrefix, OutputPort logicalSignal,
+			String value);
 
 	/**
 	 * Returns the write code for the given port if the value to be written is NoVal. May return
 	 * {@code null}, to indicate that NoVal is not supported.
 	 */
-	String getNoValWriteCode(String prefix, OutputPort logicalSignal);
+	String getNoValWriteCode(String prefix, String singletonPrefix, OutputPort logicalSignal);
 }
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/.ratings b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/.ratings
index 1f383e03ea4a41134a59e5221639a0aabeebe83a..9322aa76e0dd6a27a6a3c52dda343520bdceac01 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/.ratings
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/.ratings
@@ -2,14 +2,14 @@ Button1Executable.java 4419314d71af50239cf6933a83a0f652614cf368 YELLOW
 Button2Executable.java 3af03ceea3aa09178fe88fe630c94282de0b72f2 YELLOW
 Button3Executable.java 964fbe4e0b5282ab617c4be2bed31afa8b4f394f YELLOW
 Button4Executable.java 53db1cce9e3dfface4027f883586bf90638cd4ff YELLOW
-ButtonExecutableBase.java e8f53ecacbd60802fd37314d5c46989f83314ad3 YELLOW
+ButtonExecutableBase.java e0c755229dcc73a980247dbca5146cda6262bcf8 YELLOW
 ButtonL1Executable.java ab68cddae1d323ff0ecd7956133c44d1ef0f9168 YELLOW
 ButtonL2Executable.java 336b9d8d26a682b701f7a2ca078369c9cc621fbb YELLOW
 ButtonR1Executable.java 700ef701ed77a0d3f8141166fe647ac5cd4ad570 YELLOW
 ButtonR2Executable.java 9b4acdc37505f41c60d8216c92bcbd3f43a2ccec YELLOW
-GamepadExecutableBase.java e79e9e5823e14a15f62c8a18a4025241896e998c YELLOW
+GamepadExecutableBase.java d4b88c08dd1bd77ae3c3e24daed638ab7fbf69e7 YELLOW
 Left_StickXExecutable.java c3e7f28f44fa27bd79e14ed7e60f44be2dc5a9ab YELLOW
 Left_StickYExecutable.java f81cc1e3124eb712507825bc54e7d0f633fde640 YELLOW
 Right_StickXExecutable.java ade165c88d0c6758efa167e5ba445eff87a0fd79 YELLOW
 Right_StickYExecutable.java 891ea877d8c3f4bab6072a02b17bb92a6caa055d YELLOW
-StickExecutableBase.java 7f1fb5e30585fdb3cbafe06e3e4311cbc0f5bf21 YELLOW
+StickExecutableBase.java 65fabd5583e055a30081517d11c1986e4041c6c3 YELLOW
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/ButtonExecutableBase.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/ButtonExecutableBase.java
index e8f53ecacbd60802fd37314d5c46989f83314ad3..e0c755229dcc73a980247dbca5146cda6262bcf8 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/ButtonExecutableBase.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/ButtonExecutableBase.java
@@ -33,13 +33,14 @@ abstract class ButtonExecutableBase<T extends EObject> extends GamepadExecutable
 
 	/** {@inheritDoc} */
 	@Override
-	public final String getReadCode(String prefix, InputPort logicalSignal) {
+	public final String getReadCode(String prefix, String singletonPrefix, InputPort logicalSignal) {
 		return "gamepad_get_button_state(" + getButtonIdentifier() + ");\n";
 	}
 
 	/** {@inheritDoc} */
 	@Override
-	public final String getNoValReadCode(String prefix, InputPort logicalSignal) {
+	public final String getNoValReadCode(String prefix, String singletonPrefix,
+			InputPort logicalSignal) {
 		return null;
 	}
 
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/GamepadExecutableBase.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/GamepadExecutableBase.java
index e79e9e5823e14a15f62c8a18a4025241896e998c..dde1abb7a5cb78659cb74712b11b26c29639601e 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/GamepadExecutableBase.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/GamepadExecutableBase.java
@@ -17,8 +17,8 @@ package org.fortiss.af3.platform.raspberry.generator.executable.gamepad;
 
 import org.eclipse.emf.ecore.EObject;
 import org.fortiss.af3.platform.raspberry.generator.executable.framework.ISingletonInitializationExecutable;
+import org.fortiss.af3.platform.raspberry.generator.executable.framework.ISingletonTerminationExecutable;
 import org.fortiss.af3.platform.raspberry.generator.executable.library.PiHALLibraryExecutableBase;
-import org.fortiss.af3.platform.raspberry.model.gamepad.GamepadPackage;
 
 /**
  * Base class for all executables of the gamepad input sensors.
@@ -26,7 +26,7 @@ import org.fortiss.af3.platform.raspberry.model.gamepad.GamepadPackage;
  * @author hoelzl
  */
 abstract class GamepadExecutableBase<T extends EObject> extends PiHALLibraryExecutableBase<T>
-		implements ISingletonInitializationExecutable {
+		implements ISingletonInitializationExecutable, ISingletonTerminationExecutable {
 	/** Constructor. */
 	public GamepadExecutableBase(T modelElement) {
 		super(modelElement);
@@ -34,26 +34,37 @@ abstract class GamepadExecutableBase<T extends EObject> extends PiHALLibraryExec
 
 	/** {@inheritDoc} */
 	@Override
-	public final String getSingletonInitializationCode() {
-		return "gamepad_configuration_t* gamepad_config = malloc(sizeof(gamepad_configuration_t));\n"
-				+ "gamepad_config->device_id = \"/dev/input/js0\";\n"
-				+ "gamepad_config->waiting_sleep_in_micros = 250;\n"
-				+ "gamepad_config->axis_callback = NULL;\n"
-				+ "gamepad_config->button_callback = NULL;"
-				+ "gamepad_initialize(gamepad_config);\n\n";
+	public final String getSingletonVariableDeclarationCode(String singletonPrefix) {
+		return "static gamepad_configuration_t* " + singletonPrefix + "_gamepad_config;\n";
 	}
 
 	/** {@inheritDoc} */
 	@Override
-	public final String getSingletonVariableDeclarationCode() {
-		return "";
+	public final String getSingletonInitializationCode(String singletonPrefix) {
+		String prefixedVar = singletonPrefix + "_gamepad_config";
+		StringBuilder sb = new StringBuilder();
+		sb.append("// initialize the gamepad configuration\n");
+		sb.append("gamepad_configuration_t* " + prefixedVar +
+				" = malloc(sizeof(gamepad_configuration_t));\n");
+		sb.append(prefixedVar + "->device_id = \"/dev/input/js0\";\n");
+		sb.append(prefixedVar + "->waiting_sleep_in_micros = 250;\n");
+		sb.append(prefixedVar + "->axis_callback = NULL;\n");
+		sb.append(prefixedVar + "->button_callback = NULL;\n");
+		sb.append("gamepad_initialize(" + prefixedVar + ");\n\n");
+		return sb.toString();
 	}
 
 	/** {@inheritDoc} */
 	@Override
-	public final String getSingletonInitializationIdentifier() {
-		// use EMF package as singleton identifier
-		return GamepadPackage.eNS_URI;
+	public String getSingletonTerminationCode(String singletonPrefix) {
+		return "gamepad_terminate();\n";
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public final String getSingletonIdentifier() {
+		// use header file as singleton identifier
+		return getHeaderFileName();
 	}
 
 	/** {@inheritDoc} */
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/StickExecutableBase.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/StickExecutableBase.java
index 7f1fb5e30585fdb3cbafe06e3e4311cbc0f5bf21..65fabd5583e055a30081517d11c1986e4041c6c3 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/StickExecutableBase.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/gamepad/StickExecutableBase.java
@@ -33,13 +33,13 @@ abstract class StickExecutableBase<T extends EObject> extends GamepadExecutableB
 
 	/** {@inheritDoc} */
 	@Override
-	public final String getReadCode(String prefix, InputPort logicalSignal) {
+	public final String getReadCode(String prefix, String singletonPrefix, InputPort logicalSignal) {
 		return "gamepad_get_axis_position(" + getAxisIdentifier() + ");\n";
 	}
 
 	/** {@inheritDoc} */
 	@Override
-	public String getNoValReadCode(String prefix, InputPort logicalSignal) {
+	public String getNoValReadCode(String prefix, String singletonPrefix, InputPort logicalSignal) {
 		return null;
 	}
 
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/.ratings b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/.ratings
index 1df6817909fbf53ada1faafcd8f6a4d758012a12..bc7da89e9f4ea0911dfd4aed793ba8c66802e8f8 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/.ratings
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/.ratings
@@ -1,6 +1,6 @@
 ButtonAExecutable.java bbcb151d851b1b3d3e97b7e11b790fa13559fd96 YELLOW
 ButtonBExecutable.java d659e04dc60cba0808bd2fceae22fcbc1bd203a9 YELLOW
-ButtonExecutableBase.java 168dede764665f721862d2b7aed3a5de5668c1f1 YELLOW
+ButtonExecutableBase.java e29dff88a089470888c295886bce9d3179516424 YELLOW
 ButtonHomeExecutable.java e3a19a82d2cafd3bc75b6a7fc1a75df5656df48c YELLOW
 ButtonL1Executable.java 68fac6c2abc7ea40eb7cc16839677a4cdc24111a YELLOW
 ButtonL3Executable.java 2d04b51ee7ab822419140cf69821bbcbcfded359 YELLOW
@@ -20,6 +20,6 @@ Left_StickYExecutable.java cc2b36f9bca913dc1956f34495cf9c77acb13c88 YELLOW
 R2PositionExecutable.java 19f778392841d02d281fd856564b75e1333dffaa YELLOW
 Right_StickXExecutable.java 97656a2ae56a70eac88153b123f2cd9c584af967 YELLOW
 Right_StickYExecutable.java f3d942123ca47d0ddbf32f4f46bfaf2b21732653 YELLOW
-RumblepadExecutableBase.java 876ab9c58e37837b273bfcbbc62233ca4d0576cc YELLOW
+RumblepadExecutableBase.java a12c66ea010375e0367646444f1c0b90bf791b03 YELLOW
 SimpleRumbleFeatureExecutable.java 413b6fb3f5847f0d09f52341c98b95f74c352016 YELLOW
-StickExecutableBase.java 7004e20d199bec82752b870db259786602db9766 YELLOW
+StickExecutableBase.java b9592ed47078f82aa0e95f90f545c5ff3ee26dc4 YELLOW
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/ButtonExecutableBase.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/ButtonExecutableBase.java
index 168dede764665f721862d2b7aed3a5de5668c1f1..e29dff88a089470888c295886bce9d3179516424 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/ButtonExecutableBase.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/ButtonExecutableBase.java
@@ -33,13 +33,14 @@ abstract class ButtonExecutableBase<T extends EObject> extends RumblepadExecutab
 
 	/** {@inheritDoc} */
 	@Override
-	public final String getReadCode(String prefix, InputPort logicalSignal) {
+	public final String getReadCode(String prefix, String singletonPrefix, InputPort logicalSignal) {
 		return "rumblepad_get_button_state(" + getButtonIdentifier() + ");\n";
 	}
 
 	/** {@inheritDoc} */
 	@Override
-	public final String getNoValReadCode(String prefix, InputPort logicalSignal) {
+	public final String getNoValReadCode(String prefix, String singletonPrefix,
+			InputPort logicalSignal) {
 		return null;
 	}
 
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/RumblepadExecutableBase.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/RumblepadExecutableBase.java
index 876ab9c58e37837b273bfcbbc62233ca4d0576cc..a12c66ea010375e0367646444f1c0b90bf791b03 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/RumblepadExecutableBase.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/RumblepadExecutableBase.java
@@ -17,8 +17,8 @@ package org.fortiss.af3.platform.raspberry.generator.executable.rumblepad;
 
 import org.eclipse.emf.ecore.EObject;
 import org.fortiss.af3.platform.raspberry.generator.executable.framework.ISingletonInitializationExecutable;
+import org.fortiss.af3.platform.raspberry.generator.executable.framework.ISingletonTerminationExecutable;
 import org.fortiss.af3.platform.raspberry.generator.executable.library.PiHALLibraryExecutableBase;
-import org.fortiss.af3.platform.raspberry.model.rumblepad.RumblepadPackage;
 
 /**
  * Base class for all executables of the rumblepad.
@@ -26,7 +26,7 @@ import org.fortiss.af3.platform.raspberry.model.rumblepad.RumblepadPackage;
  * @author hoelzl
  */
 abstract class RumblepadExecutableBase<T extends EObject> extends PiHALLibraryExecutableBase<T>
-		implements ISingletonInitializationExecutable {
+		implements ISingletonInitializationExecutable, ISingletonTerminationExecutable {
 	/** Constructor. */
 	public RumblepadExecutableBase(T modelElement) {
 		super(modelElement);
@@ -34,26 +34,37 @@ abstract class RumblepadExecutableBase<T extends EObject> extends PiHALLibraryEx
 
 	/** {@inheritDoc} */
 	@Override
-	public final String getSingletonVariableDeclarationCode() {
-		return null;
+	public final String getSingletonVariableDeclarationCode(String singletonPrefix) {
+		return "static gamepad_configuration_t" + singletonPrefix + "_rumblepad_config";
 	}
 
 	/** {@inheritDoc} */
 	@Override
-	public final String getSingletonInitializationCode() {
-		return "rumblepad_configuration_t* rumblepad_config = malloc(sizeof(rumblepad_configuration_t));\n"
-				+ "rumblepad_config->device_id = \"/dev/input/js0\";\n"
-				+ "rumblepad_config->waiting_sleep_in_micros = 50;\n"
-				+ "rumblepad_config->axis_callback = NULL;\n"
-				+ "rumblepad_config->button_callback = NULL;"
-				+ "rumblepad_initialize(rumblepad_config);\n\n";
+	public final String getSingletonInitializationCode(String singletonPrefix) {
+		String prefixedVar = singletonPrefix + "_rumblepad_config";
+		StringBuilder sb = new StringBuilder();
+		sb.append("// initialize the rumblepad configuration\n");
+		sb.append("rumblepad_configuration_t* " + prefixedVar +
+				" = malloc(sizeof(rumblepad_configuration_t));\n");
+		sb.append(prefixedVar + "->device_id = \"/dev/input/js0\";\n");
+		sb.append(prefixedVar + "->waiting_sleep_in_micros = 50;\n");
+		sb.append(prefixedVar + "->axis_callback = NULL;\n");
+		sb.append(prefixedVar + "->button_callback = NULL;");
+		sb.append("rumblepad_initialize(rumblepad_config);\n\n");
+		return sb.toString();
 	}
 
 	/** {@inheritDoc} */
 	@Override
-	public final String getSingletonInitializationIdentifier() {
-		// use EMF package as singleton identifier
-		return RumblepadPackage.eNS_URI;
+	public String getSingletonTerminationCode(String singletonPrefix) {
+		return "rumblepad_terminate();\n";
+	}
+
+	/** {@inheritDoc} */
+	@Override
+	public final String getSingletonIdentifier() {
+		// use header file as singleton identifier
+		return getHeaderFileName();
 	}
 
 	/** {@inheritDoc} */
diff --git a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/StickExecutableBase.java b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/StickExecutableBase.java
index 7004e20d199bec82752b870db259786602db9766..b9592ed47078f82aa0e95f90f545c5ff3ee26dc4 100644
--- a/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/StickExecutableBase.java
+++ b/org.fortiss.af3.platform.raspberry/src/org/fortiss/af3/platform/raspberry/generator/executable/rumblepad/StickExecutableBase.java
@@ -33,13 +33,14 @@ abstract class StickExecutableBase<T extends EObject> extends RumblepadExecutabl
 
 	/** {@inheritDoc} */
 	@Override
-	public final String getReadCode(String prefix, InputPort logicalSignal) {
+	public final String getReadCode(String prefix, String singletonPrefix, InputPort logicalSignal) {
 		return "rumblepad_get_axis_position(" + getAxisIdentifier() + ");\n";
 	}
 
 	/** {@inheritDoc} */
 	@Override
-	public final String getNoValReadCode(String prefix, InputPort logicalSignal) {
+	public final String getNoValReadCode(String prefix, String singletonPrefix,
+			InputPort logicalSignal) {
 		return null;
 	}