Oops! I forgot to change database to DATABASE for my call to DATABASE's close function.
Added code to handle the edge case of a database folder not existing.