added tests and minor adjustments