small improvements for avoiding notices and having more debug info