actual first attempt, which is in a mess...
Reverted previous erroneous changes...
Fixed bugs #36 and #37.