prototype working.
fix: some memory allocation problem that
     randomly happen
cleanup code