A lot of little fixes and additions
another different fixes, pair of new debug functions