Implement functions for assignment2