Fixed loopback, cleaned up the code.