Debuged code, but slow