Separate function
Add tests