Adapted to assignment4