refactor for new struct
add more comprehensive tests
Merge remote-tracking branch 'origin/master'