Adding tests and fixing up a few things