added shutdown hook and fixed to date query