Code cleanup and commenting