Added tests and fixed up other small "bugs"