need some cleanup, added tests, works fine on OSX
added test to regression suite