fix bugs/simplify