added better write support. Will optimize later