added TA's code as a reference