adding some tests
refactoring. bug fixing.