ref counting implemented for stack functions, convenience stack functions added