SQL and common array fixes