Improved database stuff and added more functions.