Added code to handle database timeout