Move some database access out of includes/functions.php
Move enclosures stuff to own file