reorganise code, add ram argument

Change-Id: I034596c35b09d50ccc15d6865e3041d07baaf767