added logging, error checking, and changed stack to queue