fixed references, added more diagnostic logging