Completed skeleton code with actual logic