Almost done

all the code is there, need comments and testing.