Almost done, need to test the det thing at the end