Cleaned-up data handling, put logging back in