Finally sorting works as is need to work. Removed debug parts.