Refine testing code, fix failing tests

:+1: