added function for writing memory page to device