0.5.1: fixes for a few serious bugs in the code