Added tests and minor fixes