Finished problem 1.
Everything seems to work except one bug.
Added comments.
Forgot to commit last time.