added unittests, rewrote output, changed some variable to class members