Fixed the crazy if statements a bit