Midterm Finished

Added fuctions instead of repeated code
Added more comments