Major reworking following Thomas suggestions