Clean up contents code a bit