fixed comments and refined code