added ct function
fixed various missing bits