Added additional debug and logging functionality