Added test for next, improved emptiness checks. Added type and function visibility control too.