Some fixes and gernalisation