added comments and logging functionality