matrix working code cleaner