Fixes a critical error, adds new tests