fixed sql for waiting page, cleaned up SQL calls