Reorder functions; better commenting