Cleaned up, commented, added a bit more relay-related code.