Major fixes

The actual code we tested was defective and full of major errors, this
is a small step in the right direction...