Reduce complexity
Added unit test