found and fixed several bugs using tests