added some comments and utility functions