Code cleaned a bit, still needs testing to be done.