Needs debugging but i'm done for  the night