Cleaned up fromatting and foreach loops