moved imports to local functions, added debug logging