Update Database.php

Added transaction, cleaned the code