Fixed writing to wrong location