Fixed ifs, and some debugging