Replace if/error with assert where applicable
Improve edge case coverage