Tidy up memwriter
Add memwriter tests