Solution attempt 2