added tests and fixed a few issues