Data handling, and some cleaning up