finished functions
Merge https://github.com/Jiebin/ProgrammingAssignment2