Adding coverage and fixing bugs