Added redirect function. Improved DB functions