added tests and fixed io