fixed severe memory leak, added inlined isEmpty() function