remove duplicate code
add some error logging that was missing
cosmetic