Minor changes: fixed some comments and reordered some functions