added exit on failure
changed db connectivity to prepared statements