diff --git a/4-ShellP2/bats/assignment_test.sh b/4-ShellP2/assignment_test.sh
old mode 100644
new mode 100755
similarity index 98%
rename from 4-ShellP2/bats/assignment_test.sh
rename to 4-ShellP2/assignment_test.sh
index b8457627515cb75b9d1ee54d5e42882fb3f670d4..30b12ec1661cd179396f1e2ee3fd8ef39de7eb96
--- a/4-ShellP2/bats/assignment_test.sh
+++ b/4-ShellP2/assignment_test.sh
@@ -97,7 +97,7 @@ EOF
 
 @test "It handles quoted spaces" {
     run "./dsh" <<EOF                
-echo " hello     world     " 
+   echo " hello     world     " 
 EOF
 
     # Strip all whitespace (spaces, tabs, newlines) from the output
diff --git a/4-ShellP2/bats/.assignment_test.sh.swp b/4-ShellP2/bats/.assignment_test.sh.swp
deleted file mode 100644
index fde799a3ba9807e5e16e113b95332c966a0b8b85..0000000000000000000000000000000000000000
Binary files a/4-ShellP2/bats/.assignment_test.sh.swp and /dev/null differ
diff --git a/4-ShellP2/bats/.student_test.sh.swp b/4-ShellP2/bats/.student_test.sh.swp
deleted file mode 100644
index 1ac057dfda0d92c4c518a6a348665f5c3142d354..0000000000000000000000000000000000000000
Binary files a/4-ShellP2/bats/.student_test.sh.swp and /dev/null differ
diff --git a/4-ShellP2/dsh b/4-ShellP2/dsh
index 01c20559967f638402f75036f995d77937e63f65..94daff0c436fa56931a870be364ed1858e5fe478 100755
Binary files a/4-ShellP2/dsh and b/4-ShellP2/dsh differ
diff --git a/4-ShellP2/dshlib.c b/4-ShellP2/dshlib.c
index 77fb323e4887c39705c1ba3f35ccd2b74e07af5f..eaad17c279490ff128b60d0fd6340fae25d1e643 100644
--- a/4-ShellP2/dshlib.c
+++ b/4-ShellP2/dshlib.c
@@ -56,16 +56,20 @@ int alloc_cmd_buff(cmd_buff_t *cmd_buff) {
 }
 
 int free_cmd_buff(cmd_buff_t *cmd_buff) {
+	if (cmd_buff == NULL) return OK_EXIT;
+	
 	free(cmd_buff->_cmd_buffer);
-	 
+	cmd_buff->_cmd_buffer = NULL;
+	
 	for (int i = 0; i < CMD_ARGV_MAX - 1; i++) free(cmd_buff->argv[i]);
+	free(cmd_buff->argv);
 	free(cmd_buff);
 	return OK_EXIT;
 }
 
 int clear_cmd_buff(cmd_buff_t *cmd_buff) {
 	cmd_buff->argc = 0;
-	free(cmd_buff->_cmd_buffer);
+	memset(cmd_buff->_cmd_buffer, 0, SH_CMD_MAX);
 	
 	for (int i = 0; i < CMD_ARGV_MAX; i++) cmd_buff->argv[i] = NULL;
 	return OK_EXIT;
@@ -95,12 +99,10 @@ int build_cmd_buff(char *cmd_line, cmd_buff_t *cmd_buff) {
 	if ((int)strlen(cmd_line) > SH_CMD_MAX) return ERR_CMD_OR_ARGS_TOO_BIG;
 
 	if ((int)strlen(cmd_line) == 0) return WARN_NO_CMDS;	
-	
+
+	if (cmd_buff->_cmd_buffer) free(cmd_buff->_cmd_buffer);
 	cmd_buff->_cmd_buffer = strdup(trim_whitespace(cmd_line));
-	if (cmd_buff->_cmd_buffer == NULL) {
-		free(cmd_buff);
-		return ERR_MEMORY;
-	}
+	if (cmd_buff->_cmd_buffer == NULL) return ERR_MEMORY;
 	
 	char *token = cmd_buff->_cmd_buffer;
 	bool quotes = false;
@@ -176,7 +178,7 @@ int exec_local_cmd_loop()
 {
     char *cmd_buff = malloc(ARG_MAX * sizeof(char));
 	int rc = 0;
-    cmd_buff_t *cmd = malloc(CMD_ARGV_MAX * sizeof(char *));
+    cmd_buff_t *cmd = malloc(sizeof(cmd_buff_t));
 	
 	if ((rc = alloc_cmd_buff(cmd)) != OK_EXIT) exit(rc);
 
@@ -210,8 +212,9 @@ int exec_local_cmd_loop()
 		
 		// TODO IMPLEMENT parsing input to cmd_buff_t *cmd_buff
 		if ((rc = build_cmd_buff(cmd_buff, cmd)) != OK_EXIT) {
+            free(cmd_buff);
+            free_cmd_buff(cmd);
             exit(rc);
-            rc = 0;
     	}
 		/*
 		if (strcmp(cmd->argv[0], "echo") == 0) {
diff --git a/4-ShellP2/bats/student_test.sh b/4-ShellP2/student_test.sh
similarity index 100%
rename from 4-ShellP2/bats/student_test.sh
rename to 4-ShellP2/student_test.sh