Some minor modifications see the history for details