improved performance
added tests