improved undefined check, and more documentation