extensive code update
