Working but slow version