Fixed write and append
Updated version