Remove global $db from function