Added tests and fixed major and minor issues.