Added stack checking