Adds basic write function functionality. Fixes globals.