added tests, fixed some gugs