added tests
fixed minor findings
added unit tests