fixed formatting + memory management