Big fixes

Database class now uses singleton principal. Fix memory leak, crashes
and to much open connections.