* Fix tests code to prevent some runtime errors * Reduce nesting
* Helper functions for intergration test boilerplate