Minor refactoring, Add more tests