added write_ to_ memory and moved main