Fixed redundant writes and updated tests