finding refs and fixing bugs