moved pop outside try, expanded lock