writes closer to working, still needs testing