Code improvements, ctrl-c handle, and solved memory leaks