Fix some code and adjust tests