Code from Tasks 1-4