bug searching and partially fixing; cleanup