Improve performance for assignment1