Fixed up bad code in generating signatures + beefed up unit test