Test programs

Fixes, refactorings and more test programs added.