Added main write ability. Not finished yet, but stable.