fixed confusing ternary issue and added implementation comments