Fix import that fails when run tests
Add test and improve code