Cleaning up and making a bit more robust.