Optimized Queries and Fixed bug with upload validity