Fix couple of segfaults, start with tests