Completed working code for the first three problems.