Writing intensities to database and tidying up