[cleanup] Use foreach loop, use proper exception logging instead of printStackTrace