Fixes failing unit tests.  Based on @nicolasbadia's work.