Implemented Testing and minor Optimization