Added tests and fixed issues found while testing