Fixed Script
Added Query Handling