change the database script + some clean-up