Fixes bug in addChildAt and setChildIndex, and adds more parameter checking. Also adds some test cases.