Minor performance improvements
Adding tests