Added tests. Fixed minor bug