Add more tests; Some refactor