StateStack cleaning and fixing (still not fully robust); Other small fixes and API improvements