Adding documentation and reordering functions