[+] Moved some functions around to handle error control better.