added some comments and cleanup