YH-392: Added stack deletion on cleanup, cleaned up code