added more tests, more accurate code [closes #733]