More gereralisations. Added "TODO:" comments where more changes will be needed.