Use queue instead of stack, more logging