Most of the code now done