Enhance testing

While at it make minor performance enhancement