Changed deprecated constructors. Added close for db