Better implementation
Fixed tests