diff --git a/CMakeLists.txt b/CMakeLists.txt
index 434d18be8d7dcc27e808c959505f36e3a6017154..f15a650a482a4f0d8d76c677bccc1ed52c11af80 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,7 +23,7 @@ include_directories(cmsis)
 
 add_subdirectory(support)
 add_subdirectory(iclib)
-#add_subdirectory(aes)
+add_subdirectory(aes)
 #add_subdirectory(matmul)
 #add_subdirectory(matmul-tiled)
 #add_subdirectory(crc)
diff --git a/aes/CMakeLists.txt b/aes/CMakeLists.txt
index 78c5c37f83a6e6b0c06b2eaf5e6c99d447c70340..13e738444801803efe860740abe4e6869fb94b7b 100644
--- a/aes/CMakeLists.txt
+++ b/aes/CMakeLists.txt
@@ -1,15 +1,15 @@
 cmake_minimum_required(VERSION 3.0)
 
 FOREACH(METHOD "MS" "AS" "QR")
-    set(TESTNAME "aes-${METHOD}")
-    add_executable(
-        ${TESTNAME}
-        main.c
-        TI_aes_128_encr_only.c
-        TI_aes_128_encr_only.h
-        lipsum.h
-    )
-    include(${CMAKE_CURRENT_LIST_DIR}/../cmake/tail.cmake)
+  set(TESTNAME "aes-${METHOD}-${TARGET_ARCH}")
+  add_executable(
+      ${TESTNAME}
+      main.c
+      TI_aes_128_encr_only.c
+      TI_aes_128_encr_only.h
+      lipsum.h
+  )
+  include(${CMAKE_CURRENT_LIST_DIR}/../cmake/tail.cmake)
 ENDFOREACH()
 
 
diff --git a/aes/TI_aes_128_encr_only.c b/aes/TI_aes_128_encr_only.c
index 453ee3fd1b74826108c6c3697665dc7da27b0c4f..2b9a3fb80f800561499f386fd285c59b5c440aae 100644
--- a/aes/TI_aes_128_encr_only.c
+++ b/aes/TI_aes_128_encr_only.c
@@ -120,7 +120,7 @@ void aes_encrypt(unsigned char *state, unsigned char *key)
 	buf3 = state[buf4+3]^buf2;     buf3=galois_mul2(buf3); state[buf4+3] = state[buf4+3] ^ buf3 ^ buf1;
 	}
     }
-	  
+
     //key schedule
     // compute the 16 next round key bytes
     key[0] = sbox[key[13]]^key[0]^rcon;
@@ -139,7 +139,3 @@ void aes_encrypt(unsigned char *state, unsigned char *key)
     state[i]=state[i] ^ key[i];
   }
 }
-
-
-
-
diff --git a/aes/generate-reference-output.c b/aes/generate-reference-output.c
index 924af5c2943193cc1029f23c8df39cbcbc91c289..bb19fd1518ea17b54fb64ba387f14da0c8fe3a68 100644
--- a/aes/generate-reference-output.c
+++ b/aes/generate-reference-output.c
@@ -2,7 +2,6 @@
 
 #include <stdint.h>
 #include <stdio.h>
-
 #include "TI_aes_128_encr_only.h"
 
 #define MMDATA  // Empty macro
diff --git a/aes/lipsum.h b/aes/lipsum.h
index 3e0c82598c3ec58c2d8b1fe7a56bc434155c433c..232ccfeb255f9bdf5f3abb3020b71e21962cbb5a 100644
--- a/aes/lipsum.h
+++ b/aes/lipsum.h
@@ -1,4 +1,5 @@
 #include <stdint.h>
+#include "iclib/cm0_ic.h"
 
 uint8_t input[2048] MMDATA =
     "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo "
diff --git a/aes/main.c b/aes/main.c
index 1a70b03fdfe2e044806b0ba57e2c97e76750a77f..14986fd5059bf0f1bacd2dac1f1e8c95877dab85 100644
--- a/aes/main.c
+++ b/aes/main.c
@@ -1,7 +1,12 @@
-#include "test-common.h"
-#include <ic.h>
-#include <memory_management.h>
+#include "support/test-common.h"
+
+#ifdef MSP430_ARCH
 #include <msp430fr5994.h>
+#include "iclib/msp430_ic.h"
+#include "iclib/memory_management.h"
+#elif defined(CM0_ARCH)
+#include "support/cm0-support.h"
+#endif
 
 /* Benchmark includes */
 #include "TI_aes_128_encr_only.h"
@@ -15,14 +20,15 @@ static unsigned char key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
 /* ------ Function Declarations ---------------------------------------------*/
 
 int main(void) {
+  target_init();
   while (1) {
-    P1OUT |= BIT2;
+    indicate_begin();
     // AES128 in Cipher Block Chaining mode
     uint8_t *prevBlock;
     uint8_t *ptr = input;
 
     // Acquire and encrypt first block
-    mm_acquire_array(ptr, AES_BLOCK_SIZE, MM_READWRITE);
+    //mm_acquire_array(ptr, AES_BLOCK_SIZE, MM_READWRITE);
     aes_encrypt(ptr, key);
     prevBlock = ptr;
     ptr += AES_BLOCK_SIZE;
@@ -30,7 +36,7 @@ int main(void) {
     // Encrypt remaining blocks
     while (ptr < input + sizeof(input)) {
       // Acquire current block
-      mm_acquire_array(ptr, AES_BLOCK_SIZE, MM_READWRITE);
+      //mm_acquire_array(ptr, AES_BLOCK_SIZE, MM_READWRITE);
 
       // CBC - Cipher Block Chaining mode
       for (int i = 0; i < AES_BLOCK_SIZE; i++) {
@@ -38,7 +44,7 @@ int main(void) {
       }
 
       // Release previous block
-      mm_release_array(prevBlock, AES_BLOCK_SIZE);
+      //mm_release_array(prevBlock, AES_BLOCK_SIZE);
 
       // Encrypt current block
       aes_encrypt(ptr, key);
@@ -48,12 +54,12 @@ int main(void) {
     }
 
     // Release last block
-    mm_release_array(prevBlock, AES_BLOCK_SIZE);
+    //mm_release_array(prevBlock, AES_BLOCK_SIZE);
 
-    P1OUT &= ~BIT2;
-    mm_flush();
+    indicate_end();
+    //mm_flush();
 
     // Delay
-    WAIT
+    wait();
   }
 }
diff --git a/cmake/common.cmake b/cmake/common.cmake
index 61e806cd03e27f602f1d9ecce8a1e5c751159046..2c5b749e026034ddf9712e71725e90c7a8072f0f 100644
--- a/cmake/common.cmake
+++ b/cmake/common.cmake
@@ -2,39 +2,39 @@
 enable_language(C ASM)
 
 IF(${TARGET_ARCH} STREQUAL "msp430")
-include_directories($ENV{MSP430_INC}/include) # MSP430 headers
+  include_directories($ENV{MSP430_INC}/include) # MSP430 headers
 
-add_compile_options(
-    -std=c99
-    -mcpu=msp430
-    -msmall
-    #-mhwmult=none
-    -mhwmult=f5series
-    -fno-common
-    -Wall
-    -fno-zero-initialized-in-bss # We don't want to zero out whole bss on every boot
-    )
+  add_compile_options(
+      -std=c99
+      -mcpu=msp430
+      -msmall
+      #-mhwmult=none
+      -mhwmult=f5series
+      -fno-common
+      -Wall
+      -fno-zero-initialized-in-bss # We don't want to zero out whole bss on every boot
+      )
 
-# Linker scripts
-set(LSCRIPTS "-T$ENV{MSP430_INC}/include/msp430fr5994_symbols.ld")
-set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LSCRIPTS}")
+  # Linker scripts
+  set(LSCRIPTS "-T$ENV{MSP430_INC}/include/msp430fr5994_symbols.ld")
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LSCRIPTS}")
 
-# Add to search path for linker scripts (xx_symbols.ld, included by main linker script)
-link_directories(
-    $ENV{MSP430_GCC_ROOT}/msp430-elf/lib/430/
-    $ENV{MSP430_GCC_ROOT}/lib/gcc/msp430-elf/8.2.0/430
-    $ENV{MSP430_INC}/include
-    $ENV{HOME}/git-arm/fused/include/
-    )
+  # Add to search path for linker scripts (xx_symbols.ld, included by main linker script)
+  link_directories(
+      $ENV{MSP430_GCC_ROOT}/msp430-elf/lib/430/
+      $ENV{MSP430_GCC_ROOT}/lib/gcc/msp430-elf/8.2.0/430
+      $ENV{MSP430_INC}/include
+      $ENV{HOME}/git-arm/fused/include/
+      )
 
-link_libraries( # Global link flags
-    # Removing standard libs and startup code to prevent unnecessary initialization
-    -nostdlib
-    -ffreestanding
-    )
+  link_libraries( # Global link flags
+      # Removing standard libs and startup code to prevent unnecessary initialization
+      -nostdlib
+      -ffreestanding
+      )
 
-# Utility for linking targets to std libs
-set(SUPPORT_LIBS mul_f5 gcc c)
+  # Utility for linking targets to std libs
+  set(SUPPORT_LIBS support-${TARGET_ARCH} mul_f5 gcc c)
 
 ELSEIF(${TARGET_ARCH} STREQUAL "cm0")
 
@@ -66,12 +66,7 @@ ELSEIF(${TARGET_ARCH} STREQUAL "cm0")
     -mcpu=cortex-m0
     )
 
-set(SUPPORT_LIBS
-  support
-  nosys
-  m
-  gcc
-  c)
+set(SUPPORT_LIBS nosys m gcc c)
 
 ELSE()
   message(ERROR "Invalid TARGET_ARCH: ${TARGET_ARCH}")
diff --git a/cmake/tail.cmake b/cmake/tail.cmake
index 4e6e261e4b1cc282a52bcd9535e8f0b269a3250d..e4539ebaf229c59e901934283cb16b9e35bd8827 100644
--- a/cmake/tail.cmake
+++ b/cmake/tail.cmake
@@ -1,38 +1,39 @@
 cmake_minimum_required(VERSION 3.13)
 
 # Commmon function to add linker script and definitions for each target
-  message("Testname ${TESTNAME}")
 
-target_link_libraries(
-  ${TESTNAME}
-  LINK_PUBLIC ic-${TARGET_ARCH}-${METHOD}
+target_link_libraries( ${TESTNAME}
+  LINK_PUBLIC support-${TARGET_ARCH}
+  LINK_PUBLIC ic-${METHOD}-${TARGET_ARCH}
   ${SUPPORT_LIBS}
   )
 
-set_target_properties(${TESTNAME} PROPERTIES SUFFIX ".elf")
+IF(${METHOD} STREQUAL "QR")
+  target_compile_definitions( ${TESTNAME} PRIVATE -DQUICKRECALL)
+ELSEIF(${METHOD} STREQUAL "AS")
+  target_compile_definitions( ${TESTNAME} PRIVATE -DALLOCATEDSTATE)
+ELSEIF(${METHOD} STREQUAL "MS")
+  target_compile_definitions( ${TESTNAME} PRIVATE -DMANAGEDSTATE)
+ENDIF()
+
 
 IF(${TARGET_ARCH} STREQUAL "msp430")
-  #add_msp_upload(${TESTNAME})
+  target_compile_definitions( ${TESTNAME} PRIVATE -DMSP430_ARCH)
   IF (${METHOD} STREQUAL "QR")
-      target_link_options(
-          ${TESTNAME}
-          PRIVATE -T${CMAKE_CURRENT_LIST_DIR}/support/msp430fr5994-fram-only.ld
-          )
+      target_link_options( ${TESTNAME}
+          PRIVATE -T${CMAKE_CURRENT_LIST_DIR}/support/msp430fr5994-fram-only.ld)
   ELSE ()
-      target_link_options(
-          ${TESTNAME}
-          PRIVATE -T${CMAKE_CURRENT_LIST_DIR}/support/msp430fr5994.ld
-          )
+      target_link_options( ${TESTNAME}
+          PRIVATE -T${CMAKE_CURRENT_LIST_DIR}/support/msp430fr5994.ld)
   ENDIF()
-
 ELSEIF(${TARGET_ARCH} STREQUAL "cm0")
-  message("Testname ${TESTNAME}")
-  target_link_options(
-      ${TESTNAME}
-      PRIVATE -T${CMAKE_CURRENT_LIST_DIR}/support/cm0-FS.ld
-      )
+  target_compile_definitions( ${TESTNAME} PRIVATE -DCM0_ARCH)
+  target_link_options( ${TESTNAME}
+      PRIVATE -T${CMAKE_CURRENT_LIST_DIR}/../support/cm0-FS.ld)
 ENDIF()
 
+set_target_properties(${TESTNAME} PROPERTIES SUFFIX ".elf")
+
 # Emit map, listing and hex
 add_custom_command(TARGET ${TESTNAME} POST_BUILD
   COMMAND ${TC-SIZE} -A -x "$<TARGET_FILE:${TESTNAME}>" > ${TESTNAME}.map
diff --git a/iclib/CMakeLists.txt b/iclib/CMakeLists.txt
index 4f0513d978b354198eaeaf62da400a485f7ee03d..669bc35b60600c63904523b04c2e1dcd7a9fb0ef 100644
--- a/iclib/CMakeLists.txt
+++ b/iclib/CMakeLists.txt
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.0)
 FOREACH(METHOD "MS" "AS" "QR")
     string(COMPARE EQUAL ${METHOD} "QR" QUICKRECALL)
     include(${CMAKE_CURRENT_LIST_DIR}/../cmake/common.cmake)
-    set(TESTNAME "ic-${TARGET_ARCH}-${METHOD}")
+    set(TESTNAME "ic-${METHOD}-${TARGET_ARCH}")
 
     IF(${TARGET_ARCH} STREQUAL "cm0")
       add_library(
@@ -12,7 +12,7 @@ FOREACH(METHOD "MS" "AS" "QR")
         cm0_ic.h
         cm0_ic.S
         )
-      target_link_libraries(${TESTNAME} support)
+      target_link_libraries(${TESTNAME} support-${TARGET_ARCH})
     ELSEIF(${TARGET_ARCH} STREQUAL "msp430")
       add_library(
         ${TESTNAME}
diff --git a/iclib/cm0_ic.c b/iclib/cm0_ic.c
index 8738dd5639775d562852015636214e2792d0d146..2c9c64fecb914f824d03061073f49b9bc6770636 100644
--- a/iclib/cm0_ic.c
+++ b/iclib/cm0_ic.c
@@ -21,11 +21,10 @@ extern uint8_t __boot_stack_high;
 // ------------- Globals -------------------------------------------------------
 
 // ------------- PERSISTENT VARIABLES ------------------------------------------
-#define PERSISTENT __attribute__((section(".persistent")))
 
 // Snapshots
 uint32_t saved_stack_pointer PERSISTENT;
-uint32_t stack_snapshot[STACK_SIZE] PERSISTENT;
+uint32_t stack_snapshot[STACK_SIZE / sizeof(uint32_t)] PERSISTENT;
 
 int suspending PERSISTENT;        /*! Flag to determine whether returning from
                                  suspend() or restore() */
diff --git a/iclib/cm0_ic.h b/iclib/cm0_ic.h
index 147d152ac30cc48744f1a5903fee74cee7ad4d8d..73859f047aece233c049a595c589f930e98b2c10 100644
--- a/iclib/cm0_ic.h
+++ b/iclib/cm0_ic.h
@@ -1,7 +1,12 @@
 #ifndef IC_SRC
 #define IC_SRC
 
+#define PERSISTENT __attribute__((section(".persistent")))
+#define MMDATA __attribute__((section(".mmdata")))
+
 #include <stdint.h>
 #include "iclib/config.h"
 
+void _start();
+
 #endif /* IC_SRC */
diff --git a/iclib/config.h b/iclib/config.h
index 070a71dcfc153670ee04fea7413dc430e02a8261..0c612b34513f90252ac1ff703e916e15f5e673f7 100644
--- a/iclib/config.h
+++ b/iclib/config.h
@@ -13,7 +13,7 @@
 /* ------ Section sizes -----------------------------------------------------*/
 /* Allocates (plenty of) space for snapshot in FRAM. Note that these can be made
  * smaller for most apps*/
-#define STACK_SIZE 0x1000
+#define STACK_SIZE 0x400
 #define BSS_SIZE 0x1000
 #define DATA_SIZE 0x2000
 #define MMDATA_SIZE 0x2000
diff --git a/iclib/memory_management.h b/iclib/memory_management.h
index 2f8409fa5d6d0494257b0b64368d62e2ca24928a..01de05563b4f90c6f6b9213055e0187f8335a92d 100644
--- a/iclib/memory_management.h
+++ b/iclib/memory_management.h
@@ -8,8 +8,6 @@
 #include "config.h"
 
 /***************** Macros (Inline Functions) Definitions *********************/
-// Utility to put variables in the mmdata section
-#define MMDATA __attribute__((section(".mmdata")))
 
 /************************** Constant Definitions *****************************/
 
diff --git a/support/CMakeLists.txt b/support/CMakeLists.txt
index 2510d76470ff2f3a16e9c8bf74c8416f02fe1070..f642358489b114190449ee3533180eebdafd622c 100644
--- a/support/CMakeLists.txt
+++ b/support/CMakeLists.txt
@@ -1,8 +1,8 @@
 cmake_minimum_required(VERSION 3.13)
 
-add_library(support "")
+add_library(support-${TARGET_ARCH} "")
 
-target_sources(support
-  PRIVATE cm0-vectors.c
+target_sources(support-${TARGET_ARCH}
+  PRIVATE cm0-vectors.c cm0-support.c
   PUBLIC cm0.h
   )
diff --git a/support/cm0-FS.ld b/support/cm0-FS.ld
index 56fc191295b2149edae7dea64c0ec2e22e33c5d4..548d6f2a4dce66c5a51596cc662a56530ffdea84 100644
--- a/support/cm0-FS.ld
+++ b/support/cm0-FS.ld
@@ -3,14 +3,15 @@ EXTERN (__VECTOR_TRABLE)
 ENTRY(Reset_Handler)
 
 __stack_size = 0x200;
+__boot_stack_size = 0x40;
 
 MEMORY
 {
         /*rom (rwx) : ORIGIN = 0x08000000, LENGTH = 16K */
         /*ram (rwx) : ORIGIN = 0x20000000, LENGTH = 4K */
         /*invm (rx) : ORIGIN = 0x20000000, LENGTH = 8K */
-        rom (rx)   : ORIGIN = 0x08000000, LENGTH = 8K
-        nvram (rwx): ORIGIN = 0x20000000, LENGTH = 8K
+        rom (rx)   : ORIGIN = 0x08000000, LENGTH = 16K
+        nvram (rwx): ORIGIN = 0x20000000, LENGTH = 16K
         sram (rwx) : ORIGIN = 0x20000000 + 16K, LENGTH = 8K
 }
 
@@ -123,9 +124,9 @@ SECTIONS
 .boot_stack (NOLOAD) :
 {
   PROVIDE(__boot_stack_low = .);
-  . = ALIGN(4)
+  . = ALIGN(4);
   *(.stack)
-  . += 0x100;
+  . += __boot_stack_size;
   PROVIDE(__boot_stack_high = .);
 } > sram
 
diff --git a/support/cm0-support.c b/support/cm0-support.c
index 08bd162c33ab4848f9df2398644f9185a9cc42c1..fefe66793939e4c2311b89f2a4ae733ec6e3ac74 100644
--- a/support/cm0-support.c
+++ b/support/cm0-support.c
@@ -1,8 +1,8 @@
 #include <stdint.h>
 #include <string.h>
+#include <fused.h>
 #include "support/cm0.h"
 #include "support/cm0-support.h"
-#include <fused.h>
 
 void indicate_begin() {
    SIMPLE_MONITOR = SIMPLE_MONITOR_INDICATE_BEGIN;
@@ -31,7 +31,7 @@ void fused_assert (bool c) {
 
 void target_init() { return; }
 
-// Boot function
+/*
 __attribute__((optimize(1), naked, used, section(".ftext"))) void _start() {
   // Boot data (if necessary)
   extern uint8_t __data_low, __data_high, __data_loadLow;
@@ -42,3 +42,4 @@ __attribute__((optimize(1), naked, used, section(".ftext"))) void _start() {
   int main();
   main();
 }
+*/
diff --git a/support/cm0-support.h b/support/cm0-support.h
index 760bae609da45a6d59a019c2c453282aaa29e75e..04e27a621dba7e9a6f99358754cf3bb00b7fb6b4 100644
--- a/support/cm0-support.h
+++ b/support/cm0-support.h
@@ -8,4 +8,4 @@ void indicate_begin();
 void indicate_end();
 void fused_assert(bool c);
 void fused_end_simulation();
-void _start();
+// void _start();
diff --git a/support/cm0-vectors.c b/support/cm0-vectors.c
index c3d948ad37863517f3e4450599c5187a8111c4f5..3a061f422ccc5f6f7447f69e40c0361a3e002b71 100644
--- a/support/cm0-vectors.c
+++ b/support/cm0-vectors.c
@@ -24,6 +24,7 @@
 
 #include <fused.h>
 #include "support/cm0.h"
+#include "iclib/cm0_ic.h"
 
 /*----------------------------------------------------------------------------
   External References