Updated code, not yet finished

not  tested