Fixed bugs that Daniel pointed out.